- Home /
Layout Group not working when instantiate from prefab
When I instantiate a UI prefab, the horizontal layout group in my UI does not seems to work. However, it only works with either of the followings:
When I enable Pixel Perfect in canvas
When I remove the layout group component and hardcoded the UI position & size
When it's not instantiated from prefab (meaning the UI stays in runtime, but disabled.)
Here's the setup I have:
Did I miss out something?
Answer by AltaNox · Jan 09, 2020 at 04:17 PM
Try this. This is how I always work with Layout Groups.
On the layout group component check the two boxes for child controls size. Then on every child add a LayoutElement component. This is so each one of them controls its own width and height. If the children disappear after adding the LayoutElement component it's because you need to at least set something not to 0 in their width and height configurations. Try Flexible Width and Height set to 1 for every child so they will all take the same amount of available free space, or you could just set a minimum W/H too.
Also, for the always necessary sanity check, make sure that the Horizontal Layout Group is actually enabled when you make an instance of it.
It's working! Thanks alot @AltaNox. $$anonymous$$issed out this LayoutElement
Your answer
Follow this Question
Related Questions
Instantiate rect transform objects 2 Answers
Instantiated UI prefab in canvas does not render image 1 Answer
UI LayoutGroup does not organize dynamically instantiated buttons 8 Answers
Having trouble with cloning with prefabs 1 Answer
Is there a way to Instantiate a button prefab as a child of a Canvas? 2 Answers