How am I supposed to design UIs if I can't hide previous menus?

How can I toggle the visibility of UIs I’ve made in the editor window? Right now the only thing I can see is some checkbox to disable the gameobject. Problem with that being the gameobject stays disabled when the game starts and it is impossible to find a disabled gameobject with code.

Am I supposed to just assign each one to their own layer? Isn’t that abuse of the layer system? Layers don’t seem to be made for this. Tested it and it doesn’t work, toggling visibility of menus that are children of a canvas does nothing. They only respond to the “UI” layer’s visibility.

The correct way is to use the checkbox to activate and deactivate objects. Using Find is usually a bad idea anyway, since it’s easy to break (change the name of the object and you have to remember to change your code). Just use a public variable and drag the appropriate object onto the slot in the inspector.

–Eric

2 Likes

Use empty gameobjects as parents of the menus you want to hide and use the recttransforms to anchor them (empty GO’s) down over the screen. That way you can put the menus (children) anywhere you want in the scene using a simple script that put’s them at position 0 again at game-start and they’ll be exactly where you want them.

Additionally I use canvas group components to hide them during gameplay until summoned, among other things.

1 Like