Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Layout not updating when TMP Input Field under a layout group is modified

Discussion in 'UGUI & TextMesh Pro' started by ville-ps, May 31, 2021.

  1. ville-ps


    Sep 17, 2018
    Unity 2021.1.7f1, TMP 3.0.6
    Should be reproable in other Unity versions too

    1. Add a TMP Input Field to a scene
    2. Move it under a parent object that has a HorizontalLayoutGroup
    3. Enable only the "Control Child Size: Width" option
    4. Edit the text in the input field
    What I expect: The width of the input field rect transform increases to match the preferred width driven by the parent layout group
    What happened: The width stays the same and only updates if the parent layout group is updated by e.g. deactivating and activating it

    I investigated the source code of TMP_InputField and found the cause to be a failure to call LayoutRebuilder.MarkLayoutForRebuild in Scripts\Runtime\TMP_InputField.cs:3253 if the game object does not have a ILayoutController component attached. In reality the parent controller should also be taken into account. m_IsDrivenByLayoutComponents seems like an unnecessary optimization that causes this bug as MarkLayoutForRebuild is already optimized internally.