- Home /
How to access children in script attached to gameObject
I have a gameObject "Card1", that has 11 children "CardSuit1"-"CardSuit11"
The included script is attached to Card1:
I thought this script would set up an array of gameObjects containing all the children.
Then I could use this array, for example, to deactivated one or more of the children.
However, when I run the game, I get the message : NullReferenceExeption: Object reference not set up to instance of an object (wrapper stelemref) object.ste;mref (object.intptr.object).
The game runs, but the two children that the script tries to deactivate are not deactivated.
I've searched similar questions in the forum and I really thought this should work. Anyone know what is wrong?
Answer by fafase · Jul 11, 2013 at 11:49 PM
You should post the code here instead of a picture, it is easier to read.
For you issue, you need to instantiate the array:
var array:GameObject[] = new GameObject[size];
Also your gameObject.SetActive(true);is not doing much here, if the method runs it emans the object is already active.
Thanks, this did the job. I'm new to Unity and the forum. I'll remember your comments for next time.
If this answered your question, please click on the checkmark to close the question out. Thanks.