Unity UGUI Scroll View with variably sized Text Mesh Pro

A quick note to explain how to set up a Unity UGUI Scroll View to work with Text Mesh Pro members that have arbitrary text.  The problem is the text can be any size.

The solution is:

Screenshot 2018-06-13 10.14.17.png

  • Content (the Scroll View’s Content transform):
    Vertical Layout Group (Child controls size: true)
    Content Size Fitter (Horizontal and vertical fit: Preferred size)

    • Text container “ListItem-01” etc:
      VerticalLayoutGroup (Child controls size: true, Child force expand: true)

      • TextMeshPro “ItemText-01”:
        ContentSizeFitter (preferred size)

The innermost ContentSizeFitter (on the text) relays the size the TMP member wishes to be to its parent VerticalLayoutGroup which, since “child controls size” is set allows it to be that size.  That VLG (on the list items) relays its size to the parent VLG which, since again “child controls size” means it will be allowed to be that size.  This means the content area is correctly too big for the scroll-view which causes the ScrollRect to do the scrolling we so desire 🙂

p.s. by “relays” etc here, I mean the LayoutGroups are querying their children.

References:

  • Quick answers from the “HowTo“.
  • More explanation from the Manual.
  • The source for the ultimate answers!

Leave a Reply