- Home /
Nullreference on gameobject with seeker
Hey i have tried to make a Object with an seeker attached to it but keeps giving me this error.
NullReferenceException: Object reference not set to an instance of an object
internal var seeker: Seeker = GetComponent(Seeker);
//Find closest object with certain tag
seeker.StartPath(gameObject.transform.position, closest.transform.position);
Can someone please give me some afvice on how to fix this?
Answer by Democre · Nov 20, 2012 at 12:35 AM
It means that the GetComponent is returning null. This most likely means that the Seeker script was not added to the object.
If you are trying to add a Seeker script programmatically, use AddComponent
this was correct for some reason the prefab with the seeker component wasnt added to the ones already in the scene.
Thank you
Answer by sparkzbarca · Nov 20, 2012 at 12:38 AM
Which line is the error on?
Could be one of two things
A. There isn't a Seeker Component attached to the gameObject this script is attached to so seeker isn't equal to anything
B closest which i can see is in here but not what it is may not be equal to anything
Fix A by adding a Seeker Component you could even use a RequireComponent Seeker in the gameObject code so it throws an error if a seeker isnt attached.
fix B by having closests actually equal something
Your answer
Follow this Question
Related Questions
Array index is out of range - A* Open list. 2 Answers
Need some help with a NullReference Error 3 Answers
A* problem 0 Answers
Another Null Reference Exception 0 Answers