- Home /
NullReferenceExeption
Hello friends,
can someone help me please? I have a script called Arrow wich holds the setttings of the arrow. There are multiple arrow gameobject in the scene.
I have another script called PlayerControl. with a array called arrows of type GameObject[] I created a list direction for the direction with can be set in the arrow script.
To get the direction i wanted to do this in PlayerControl:
private void Start()
{
foreach (GameObject arrow in arrows)
{
Debug.Log("foreach called");
string direction = arrow.GetComponent<Arrow>().direction;
directions.Add(direction);
}
}
But when i want to try this i got the following error: NullReferenceException: Object reference not set to an instance of a object (assests/Playercontrol.cs:19)
Which is this line: directions.Add(direction);
I do not understand what the mistake is cause string direction is set.
greetz
Answer by wdpower · Jul 30, 2017 at 11:10 AM
Solved:
Added directions = new list(); to the start function
Your answer
Follow this Question
Related Questions
Game Analytics & Facebook sdk android build error 1 Answer
Null Reference Exception 0 Answers
Character moving forwards before pressing anything 0 Answers
"Error building Player" WebGL build error 2 Answers
Roll a ball - ball not moving 2 Answers