- Home /
vertical layout problem using prefab buttons
Hello, i am experiencing a problem when trying to use a vertical layout with a series of buttons in a scroll view.
i followed the tutorial here https://unity3d.com/learn/tutorials/topics/user-interface-ui/scroll-view to create my scroll, view, and everything seems fine when examining my non-prefab button (ie, the one that exists in the hierarchy after i create it, see below).
However, when create a prefab and then instantiate and add dynamically, they don't appear as the correct size (see below, the red and green buttons with the images are the prefab buttons), they are somewhat smaller in both width and height.
i have a vertical layout and a content size fitter attached to the content of my scrollview, and my buttons have layout elements of a certain min width and height.
does anyone know why instantiating a prefab would mess up the button dimensions, while the button in the hierarchy remains the correct size.
Answer by pypython-python · Aug 20, 2020 at 06:53 PM
I had the same problem. Try setting the parent in the call to instantiate like this Instantiate(GameObject, Parent);
,try setting the parent in the call to instantiate like this Instantiate(GameObject, Parent);