My Scroll View elements (prefabs one) scaling isn't right when created on a smaller window

SOLVED (see the post below) but I don’t like the solution, I think Unity engine should doing the scaling automatically whitout hardcading it. So is that a bug ???
Hi,
I have a scroll view whose Elements are prefabs.
The prefab is a simple gameobject containing 2 UI Buttons.
I add them on the Content object (child of the viewport) with a vertical layout.
This is OK.

If launch the game in editor and prompt my panel containing the scroll view, the latter is well populated withs my prefabs instanciation.
Then I resize the window and the panel and the scroll view elements (prefabs instantiation) are correctly resized as well. Which is logic i have a Canvas Scaler : Scale with screen size activated.

But the issue is when I close my panel and reopen it : The prefabs are instantiate again but without taking the care of the proper scaling !

here is a video of the issue :

Thx for any help about this. :wink:

Ok so I solved this by Hardcoding the localScale of my prefab when i instanciate them to be equal of the root.localScale :

GameObject go = Instantiate(entryPanelTemplate) as GameObject;
          

            // Have to do this cause if we instantiate our Load/Save Entry element on our scroll view
            // the scaling is not properly cascaded down on them ... (BUG of Unity ?)
            go.transform.localScale = transform.root.localScale;

Where entryPanelTemplate is the variable that store my prefab (corresponding to an entry of the list displayed in the scroll view).
So this is working :

But I think Unity engine should have properly cascaded the scale automatically, so is that a bug of Unity ???

1 Like

thanks for posting this. helped me out tons!