GUI control has misaligned text after changing container's font size

Heya, I’ve run into a bug where a GUI control’s text becomes uncentered after changing its container’s font size.

When the container’s font size is changed after child controls have been created, then their text’s position is corrupted. The control seems to be still using the original font size for positioning, instead of recalculating the text’s position based on the new font size.

The easiest way to reproduce the issue is to use the GUI editor to add a text button (or any other input control with text), then change the root container’s font from 18px to 9px, e.g., and the text will no longer be centered.

Changing the button’s font size causes the same misalignment. Changing the text block’s font size directly fixes the issue, but being able to resize the font for all of the controls at once would be much more convenient of course, using the root container’s font size.

The same issue occurs when using javascript to change the root container’s font size on window resize, so I can confirm that it’s not just a GUI editor issue…

P.S., saving to snippet server fixes the horizontal centering issue, but not the vertical centering issue, so it’s best to re-create the issue from a new GUI, to see how it looks before it’s saved I think, but here’s a screen shot for example (zoomed in a bit to see the misalignment easier).

I’ll bring in our GUI expert @msDestiny14 for this one :slight_smile: (I can also take a look at this tomrrow if you’re busy)


Yep this looks like a bug in GUI system for children alignments. Though I wonder if it’s just a visual bug and since it corrects itself once its saved :thinking:

Let’s log it and take a look to getting that fixed.

1 Like

Only the horizontal alignment is corrected on save thou, so when setting the root container’s font size on window resize for example, the vertical misalignment issue is still present even after saving…

Edit, here’s a playground to repo the issue. :slightly_smiling_face: The GUI for it was made by just adding the button and saving, without changing the font size or anything else from the GUI editor. Then after setting the root container’s font size in javascript the vertical alignment is off.

Interestingly, I also tried making the button directly from javascript and in that case the button maintains its proper centering after changing the root container’s font size.

Edit2, the same issue happens with the InputText control too, so it’s not just the button creation that’s the issue, that’s all I can confirm from my testing thou… :thinking:


Is it happening mostly with text? Or what about images inside buttons.

I’m curious if this is a editor issue, serialization or both? Thank you for your repros. I have hunches to where some of the issues could be happening. You code reproduction using pure Javascript could be a big key!

Here is the issue on git hub. Issue on Alignment for Text · Issue #11338 · BabylonJS/Babylon.js · GitHub


The buttons with image as child (and no text) look good on font resize from JS, so do the labels made from the Text control. Thanks again! :slightly_smiling_face:


Here is the PR fix. Looks like we were not recalculating after the first render.

1 Like