c# – How in Unity make width of a rect transform object adjust to child objects increasing from one side

Just a note about the terminology: The issue that you are facing is with your implementation of the HorizontalLayoutGroup (I hope that this note will also increase the post visibility for people using search engines to find a similar solution)

You mentioned that you’ve used the anchor, but the this is not an anchor releated issue, because you are dealing with expansion to a specific direction; Anchors only give your object a range to expand to, so they can control if the object can expand on the x or on the y axis. you locked both anchors to the same position so you’re not giving the object a range of freedom in that regard anyway (you’re using the LayourGroup for that), so it’s completley unrelated to them.

Solution:

What you want to do is to change the Pivot to be at x: 0 y: 0.5
(all the way to the left),

it’ll make the RectTransform expand only to the right, as expansion direction is relative to the pivot.

Read more here: Source link