How to show and hide an ui canvas element in 2019?

I am now using Unity3D 2019, and I was already new in 2018… The task of hide and show elements of the game is tricky to me, depends on what is understood by “hide”. I have a playable character that I change the layer to an invisible layer to hide it, and it works fine (I mask the layer 31 in the camera for this purposes). But I have a dialog balloon that is inside Canvas, that got it’s own layer already, to hide all canvas is not an option so I will have to hide my text by other methods.

I did this research several times and there is a discussion about what is the best method to do so. Though changing alpha to 0 might work but might be not the best practice because it will be still processed every frame. Also there is some new features about it in 2019 version, but in the blog it is only related, there is not much of details…

So what is the best way of to show and to hide an ui element inside a canvas, by the perspective of 2019 version?

I didn’t hear of new ways to show/hide gameObjects in Unity2019. Basically, your objects are invisible as long as their Renderer / Graphics MonoBehaviour is disabled. For instance, you could do something like that:

myDialogBalloon.GetComponent<Image>().enabled = false;

But it will only disable the background of your UI balloon. If what you want is to completely disable the UI element, you should consider deactivating the gameObject (which will disable all MonoBehaviours on it and on its children)


I suggest disabling the Canvas in some situations like the following…

Coroutines cannot start on disabled GameObject so if the canvas GameObejct is disabled then all its children will be as well.

So how about **canvas.enabled = false; ** when hiding that canvas.

Setting alphas to 0 might “hide” a graphic but if it’s an interactive button it’s a hidden interactive element you might not want to be active for clicking on it.

It’s easy! Go to your Hierarchy and use the eye icons, which were previously in the Layers dropdown. Toggle the eye icons next to relevant GameObject(s) to hide them in the Scene but preserve them in the game.