Canvas group alpha won't change

Hi all,
I’m unsure if I have posted this to the appropriate subforum. In case I find its solution I post it to both places.
The issue is that I can’t change the canvas group’s alpha not by code, nor via the editor.
the line of code I use:

ExitButton.GetComponent<CanvasGroup>().alpha = 0.0f;

I just have no idea what the issue might be.
EDIT: if I use the canvas renderer.SetAlpha, it disappears for a moment then it is visible again.

1 Like

I’m using .alpha in one of my projects and it’s working just fine.
Are you perhaps resetting the alpha back to 1 somewhere else?

No, I’m not touching it anywhere else. What is more, as I have this on an OnClick event, it runs only once (if I click it once).
And as I said, I can’t even change the alpha during runtime in the editor, so I can’t type another value in and I can’t drag it.

Sounds like Brathnann said: Probably there’s another script somewhere that changes the value back to 1. This is the one you need to find and fix.

Might help, if you delete just that one GameObject (the exit button on which the CanvasGroup component is on) in the editor. Then you create it again, link back your (one) script that should set alpha to 0.
After doing so, all the other scripts that might have been connected, should not find your new button anymore. Result should be that you can now change your alpha in the editor and the script should work correctly, but perhaps another script now throws an error as it can’t find the button.

If that doesn’t fix the problem, it could be helpful to see more lines of your code - the problem is not in the line you posted.

Could be another UI component overriding it, doesn’t have to be one of your scripts. What does the canvas hieracy/structure look like?

Thanks for the help, but I realised this fade in and out isn’t really working with the overall design, I changed it to some rotating animations, but that hardly works as it should :smile: if you have the time, I would like you to look at the post I made under the animation tab.

me too

Sorry for resurrecting this thread, but I think some properties cannot be changed via code if you animate it using an animator. That happened to me as well.

1 Like

I’m a bit new at this but, my problem was when I tried to use the Canvas Group alpha with a sprite. It appears it only works with UI elements and my sprite wasn’t a UI element.