- Home /
MissingComponentExceptions on CanvasGroup that exists in Inspector
I'm trying to set the alpha value of a CanvasGroup from a script but I keep getting MissingComponentExceptions stating that the CanvasGroup doesn't exist on the GameObject I'm referencing. The CanvasGroup is present on that GameObject in the inspector and I even recreated the GameObject to see if there was something broken with that particular GameObject because I've been having some issues where scripts are losing their associations with UI GameObjects. It still gives me those errors. I even resorted to using GetComponents<> to print the CanvasGroup, but it couldn't find it, either.
Is there some trick to accessing CanvasGroups from scripts? I've done it in different projects in the past and didn't have any issues. Is my project just plain screwed up?
hideCanvas(roundStartScreen.GetComponent<CanvasGroup>(), true);
//roundStartScreen is defined in the inspector
public void hideCanvas(CanvasGroup cg, bool hidden)
{
if (hidden == true) {
// Debug.Log("Hiding " + cg.name);
cg.alpha = 0;
cg.blocksRaycasts = !hidden;
cg.interactable = !hidden;
}
else if (hidden == false)
{
Debug.Log("Unhiding " + cg.name);
cg.alpha = 1;
cg.blocksRaycasts = !hidden;
cg.interactable = !hidden;
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
UI Minimap 0 Answers
,InputField backspace returns already send text 0 Answers
Restarting or going in menu after finishing the game problem. 0 Answers