4.6 Newly Instantiated UI Prefabs Are Not Visible?

I’m trying to create button prefabs for some of my UI buttons and icons, however whenever I instantiate a new one from a prefab it’s completely invisible.

If I drag and drop the prefab in the editor onto the scene it also goes in as invisible. Though, if I drag and drop it into the hierarchy under the panel it’s supposed to sit under it shows up like normal. If I take the “invisible” object and drag it in the hierarchy under the appropriate parent it continues to be invisible. The same thing happens if I instantiate the object in code, and then assign it’s parent to the appropriate panel via code, it remains invisible.

What is going on here, and how do I fix it?

Thanks!

1 Like

I found I was having a similar problem when I was instantiating ui prefabs during an Awake() method upon starting the Application. I found the solution was to do the prefab instantiation in the Start() method instead. I imagine in my case, the UI objects would have been created before the canvas was ready for them and thus remained invisible during the application.

In editor you have to drop it to panel directly. In game, you should use Instantiate (yourPrefab,false); to instantiate UI elements and assign it to your panel.

Somehow, mine got a scale of zero when it instantiated and I didn’t notice it. That may be worth checking.

All UI Components has to be children of a Canvas to be visible.