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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    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

    ville-ps

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

    Repro:
    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.