Changing the text on a TextBlock in an AdvancedDynamicTexture changes vertical position upwards

Hi all,

I am new to BJS (and for that matter the whole topic of rendering) and while toiling the docs I noticed that re-setting the text on a TextBlock that has already been added to an AdvancedDynamicTexture changes the text’s vertical position upwards.

Here is the docs example I am modifying, and here is a working (broken) example:

  • changing the text while the TextBlock is attached breaks vertical position
  • removeControling and re-addControling the TextBlock breaks vertical position
  • removeControling the TextBlock and creating a new one works fine

Not part of the playground, but tested: The position change only happens for TextBlocks that had previously been addControled to the AdvancedDynamicTexture, creating a TextBlock and wildly changing the text on it before addControling it makes no difference.

Am I missing something obvious or is recreating TextBlocks all the time the standard method of updating text or is this a bug?

cc @georgie

1 Like

taking a look!

If you set the flag resizeToFit to true, you can change the text after creating the textblock. Here is a playground with the flag applied!
Simple GUI in fullscreen mode | Babylon.js Playground (babylonjs.com)

And here is the place in our docs where this is highlighted

Thanks for the guidance!

I was a little confused when changing the text back to it’s original did not revert the positional change. Is that expected? I had expected the TextBlock width and height to be persisted (without enabling resize to fit) and thus identical text to be positioned identically as well, but I guess that is not how it works :smiley:

Anyway thanks!

The textblock’s width/height is dynamically adjusted based on the text it contains so it is expected that changing the text would modify the height however I agree it is unexpected that reverting to previous text does not revert to previous height. This may be a bug, I will investigate!

Thank you for reporting, it was indeed a bug! Fix incoming
Fix layout shift when modifying textBlock text by georginahalpern · Pull Request #17187 · BabylonJS/Babylon.js

1 Like