- Home /
Null Reference Exceptions
Getting a NRE with this code, which seems pretty simple to me. Claims that the Respawn call is not getting a reference.
if (Input.GetButtonDown ("Respawn"))
{
RespawnManager.Respawn (this.gameObject);
}
This is a problem I seem to come up against quite often - I simply what to refer to the parent gameObject of the script, and there doesn't seem to be a easy/consistent way to do this. I can acquire the position of the Parent using gameObject.transform.position, but gameObject gives an NRE. I had hoped that this.gameObject would solve it, but no dice.
I'm at a loss at this point. Going to step away for a bit, check back in tonight.
Answer by IMoriarty · Dec 05, 2011 at 04:23 AM
Answer: I'm an idiot! Found the answer after some more head pounding and totally reassembling a few parts - Punchline: Make sure the script RespawnManager is actually attached to the object you're attempting to reference.
After all that, the gameObject was not actually the NRE, it was the Script/Function combo.
Oh well.
Your answer

Follow this Question
Related Questions
Instantiate giving a NullReferenceError 1 Answer
NullReferenceException: Object reference not set to an instance of an object 2 Answers
MoveTowards doesn't work after changing tag. 2 Answers
NullPointerException while changing a variable from one script in another 1 Answer
array initialisation c# 1 Answer