- Home /
Canvas Scaler with Vertical Layout Group and Elements Not Scaling at Runtime?
I am working on an inventory application and I am encountering a strange situation in regards to the scaling of my "product panel objects" when instantiated into the vertical layout group. If I start the application at the reference resolution (320x480) and then scale to any resolution my elements get scaled appropriately, but if I start the application at anything other than the reference resolution first, my objects wont scale inside the vertical layout group correctly. I've tried a few setups with the elements but currently they are set to stretch horizontally to fill the object. I've tried both min height and preferred height (40px)
: the objects in the vertical layout group with names and eans are generated at runtime with data from an xml file. I have added a blank prefab object in both screens to demonstrate how it should look/fill :
[started at 720x1280]
https://www.dropbox.com/s/vajmyios1oe3hwn/Screenshot%202015-03-07%2013.21.33.png?dl=0
[started at 320x480 and then scaled to 720x1280]
https://www.dropbox.com/s/4ifu2s5u9jurstm/Screenshot%202015-03-07%2013.21.56.png?dl=0
Answer by PhusionDev · Mar 07, 2015 at 08:23 PM
I seem to have figured it out after many attempts to adjust the layout and rects, the fix was in the code when instantiating the product panels. I simply changed the following line of code:
newProductObject.transform.SetParent(productContentPanelObject.transform)
to
newProductObject.transform.SetParent(productContentPanelObject.transform, false)
thank you Runevision (of unity) in this post for the lead! http://forum.unity3d.com/threads/scrollrect-runtime-content.263815/
Brilliant! Saved me hours of trying to experiment with layout settings. Thank you!!!