- Home /
Weird UnassignedReferenceException bug
Hi, I found a very weird bug. If i do this
void Update () {
if(p2!=null)
{
Debug.Log("p2 exsists");
Debug.Log(p2.transform.position);
}
}
then it runs and prints the position out
if i then drop the test and do this
void Update () {
Debug.Log(p2.transform.position);
}
then it still prints out the position but it also puts out the UnassignedReferenceException error twice per frame.
Nothing else is changed and the gameobject p2 is a public variable and assigned in the inspector
Hi, strange, something must set it to null: did you try a "if (p2==null) then log something" ?
I guess you have multiple of those objects in your scene (the one containing the script with Update(), because there are 2 exceptions logged per frame). $$anonymous$$aybe one (two) of them doesn't have the p2 field set in the inspector ? Or maybe you instantiate one of those "object with this script" from a prefab that have the p2 field null ? Did you try log the this.name + this.gameObject.GetInstanceID() of the gameObject when (p2==null) ?
Answer by KEELAN · Aug 30, 2014 at 01:45 PM
Very sorry, i was making a dumb error. I duplicated the object with the script. So there were two objects with the script and only one had p2 assigned. Didnt see that. Again, apologies
regards
Your answer
Follow this Question
Related Questions
Editor Camera moving while rotating 0 Answers
My first time launching Unity and i have no text plz help 1 Answer
Object flips 90 degrees when I add a box Collider - strange 0 Answers
Changing Skybox tint in game, permanently changes it in editor? 1 Answer
Unity instantly crashes when switching from game to scene view. 2 Answers