Make UI elements invisible

I need to make a UI button invisible, but not by the command SetActive(false) because I need a script on it to run.
I tried below commands but none of them works, seems they are obsolete or wrong


It seems there is no enabled property for renderer or canvasRenderer in Unity 5.
any solutions?

I usually do this to hide UI stuff:

Add a Canvas Group component to the root object you want to hide (just the root, the childs don’t need the component)

Setup a reference to that Canvas Group on the script that should hide the UI element.

Say you named “canvasGroup” the reference to the Canvas Group component, then call this code whenever you want to hide it.

void Hide() {
    canvasGroup.alpha = 0f; //this makes everything transparent
    canvasGroup.blocksRaycasts = false; //this prevents the UI element to receive input events

Do the opposite to show it again

void Show() {
    canvasGroup.alpha = 1f;
    canvasGroup.blocksRaycasts = true;

Set scale to 0,0,0 also works in most circumstances (can cause some issues if you’ve got complex 3d objects in a world camera usage though). You just set it back to its live scale whenever you want it ‘enabled’.

I created a Youtube video which answers this question

Essentially you add a Canvas Group component to the Canvas with the controls you want to make invisible and access the Canvas Group in code and make it invisible and/or not interactive.
    CanvasGroup.alpha = 0f;
	CanvasGrouop.interactable = false;
	CanvasGroup.blocksRaycasts = false;

You can have multiple Canvas objects with different controls occupy the same area on the screen.

You could try making a new tag assigned to the buttons you want to be invisible and excluding them in a custom layer. If you use that layer on your camera it should render everything but the UI elements with the new tag.