Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

UI Layout Group gets not updated correctly when text size changes

Discussion in 'UGUI & TextMesh Pro' started by DannyHellfish, Mar 27, 2019.

  1. DannyHellfish

    DannyHellfish

    Joined:
    Jan 20, 2014
    Posts:
    29
    Hello,

    I want to have a background image which adjusts to the size of a textmeshpro UI label in front of it. The text of the label gets changed during runtime.

    The problem is that the layout gets not updated when the text changes but only after I deactivate the game object and activate it again.
    • I have a horizontal layout group with a content size fitter set to preferred size and the child force expand set to true.
    • The image and the label are both children of the horizontal layout group.
    • The image is anchored to the size of the layout group and has a layout element with "ignore layout" set to true.
    • The textmeshpro text label has a content size fitter set to preferred size.
    The whole setup works but when I change the text I have to deactivate the layout group, wait for at least a frame and activate it again for the changes to take place. During that frame the layout group is visible broken/flickers.

    It's probably the same issue as this one: https://forum.unity.com/threads/force-immediate-layout-update.372630/ but the suggested solution doesn't work. I tried to force the layout update via the layout group or through the general layout system and also forcing the rect component of the text mesh pro gui doesn't work. I showed the problem to the Unity team at GDC and was asked to make a forum thread so here it is :)

    I have this problem with every layout group that has dynamic text labels or content that changes in size during runtime.

    Unity 2018.2.15f1 with TextMeshPro 1.3.0

    Best,
    D
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,078
    I solved this problem with Better UI 2.0 (Beta). See here.
    If you are interested in trying it out, please write me a PM. I probably will release a second beta version next week.
     
  3. DannyHellfish

    DannyHellfish

    Joined:
    Jan 20, 2014
    Posts:
    29
    @Hosnkobf Good to know that there is a solution for this but I still hope for one that does not require an external plugin. It seems to be such a basic UI feature that I can't believe that there isn't a native Unity solution for this.