- Home /
Question by
RageGolem10 · Jan 01, 2015 at 07:33 PM ·
errorarrayobjectnullreferenceexception
Error putting an object into an Array
So I'm trying to put an Object into an Array for use later and I'm getting an error every time I try. Here's my code:
var children : GameObject[];
var temp : GameObject;
function Start ()
{
children[0] = transform.Find(this.name).Find("Teal Circle Sprite").gameObject;
Debug.Log("Name of object is" + children[0].name);
}
Here's the error that I'm getting: NullReferenceException: Object reference not set to an instance of an object Dot.Start () (at Assets/Scripts/Dot.js:8)
Some more information: The name of the class is Dot and the object in question has a child called "Teal Circle Sprite"
Any help would be great! Sorry I'm kind of new at Unity!
Comment
For this kind of error it's best to look at what values you have in your code.
children may be null.
transform.Find(this.name) may be null.
transform.Find(this.name).Find("Teal Circle Sprite") may be null.
You should Debug.Log these 3 values to figure out which is the culprit.