Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to change the text's RectTransform while having a LayoutGroup parent?

Discussion in 'UGUI & TextMesh Pro' started by OriginalACEE, Apr 28, 2023.

  1. OriginalACEE

    OriginalACEE

    Joined:
    Apr 1, 2023
    Posts:
    1
    Ok, I've searched high and low and can't seem to find a solution to this relatively simple problem. In my project, I have a parent object named SessionTag, which contains 2 elements, and image (colored circle) and a text object. During runtime, the text changes dynamically to reflect which "tag" is selected. The problem lays when the text changes to something longer then the bounding box it is set as, it is no longer centered on screen.

    Example of how it should work:



    *Notice that the text fits inside its bounding box



    Example of the problem:



    *The text leaks out of the bounding box



    The layout is as following:



    The parent has a horizontal layout group and a content size fitter,
    the text has a layout element component with flexible width turned on and set to 999
    the session color parent also has a layout element component with flexible width turned on and set to 999
    and inside of it, the SessionTagColor is just an image centered to mid-right.

    The only solution to this problem I could think of is using a Size Fitter component, however, because the text layer is a child of a horizontal layout group, I can't.

    Anyone has any suggestions?