- Home /
Change layer of a in runtime instantiated UI object
Hey guys,
I have a button which I create in runtime. I would like to change the layer in which the button is rendered. As far as I know, u can't change the order of a layer of UI objects inside the same parent Canvas. That's why I created a second Canvas with another layer. But when I create the button it always gets attached to the wrong Canvas with the wrong layer.
I tried to create a new button prefab out of the new Canvas, but still as soon as I instantiated the button it always becomes a child to the wrong Canvas.
Is there anything I can do?
Can you post a screenshot of your inspector so we can see your canvas setup? Additionally, are you setting the parent of the newly-instantiated prefab to the correct canvas? As in Instantiate(prefab, parent) kinda-deal.
Yes i do. I create a new Canvas and within a the button i wanna create in runtime. I make a prefab out of the new Canvas. I make a prefab out of the button from the right new Canvas. I delete the botton out of the new Canvas prefab. I create the button with the help of its prefab. And still it a child of the wrong parent Canvas.
Btw the screenshot is of the old Canvas, but both of them are identical