# Unity adding objects through script to scrollview (SetParent): Objects overlap

I need to add X objects to a scrollview. I do it like this:

GameObject statsObject = Instantiate(instance.statsObjectPrefab);
statsObject.transform.SetParent(statsParent.transform);


statsParent is the content container if the scrollview.

Scrollview
---- Viewport
-------- Content // This is statsParent


In the pause I see that then objects are added successfully, but they all overlap and no scrollbar is visible.

The content has a content size fitter and a vertical layout group, but I tried now all settings and the result is always the same.

I use Unity 2019.2

• Best way to work with that is to use layouts. like grid layouts as simply set right size for contents and you dont need to care for anchors after instantiation – virtouso Sep 13 '19 at 21:49
• Presumably you tried SetParent(statsParent.transform, false)? – DMGregory Jun 21 at 2:03
• Did you try LayoutRebuilder.ForceRebuildLayoutImmediate after adding the object? – Safa Jun 21 at 9:13