- Home /
Setting the alpha of an instantiated Canvas
I'm instantiating a canvas from Resources, which has a Canvas Group. When this is created, I want to immediately set the alpha to 0, and set it to 1 later. I'm having trouble accessing the component after instantiating through. here's what I've got in my Start(){}
var DialogueCanvas : Canvas = Instantiate(Resources.Load("DialogueCanvas", Canvas));
DialogueCanvas.GetComponent("CanvasGroup").alpha = 0.5;
But this doesn't work. Am I accessing the clone incorrectly? Do I need to put the component into a separate variable? I can't find good documentation for this.
Answer by Eric5h5 · May 29, 2015 at 11:20 PM
Don't use quotes when using GetComponent, since that makes it cast to Component, instead of the correct type. Also it's slower.
Ahh great, thanks, iI thought it had to be quoted. I've done it now with this line:
DialogueCanvas.GetComponent(CanvasGroup).alpha = 0;
Your answer
![](https://koobas.hobune.stream/wayback/20220613200422im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Fading between two objects in UnityScript 0 Answers
turn off interactable without changing alpha 0 Answers
How can i make this script work in a "loop"? 1 Answer
Unity UI - Fading Canvas/Panel 7 Answers