Unassigned reference is assigned and works despite the error... help!
Hi there, the situation is in the title. I'm trying to move a door upwards to open it to go to the next level once the victory condition is met. The door is a child to another game object that contains it as well as its framework and a light behind it, and the script is attached to the parent door. The variable in question is the child door, which I assigned by both using GetChild AND setting it up from inspector, yet in both situations i get the unassigned reference error. What's worse is that the whole thing works perfectly and the door moves, but I just keep getting the error. It's driving me crazy.
Relevant code:
metalDoor = transform.GetChild(1).gameObject;
if (main.victory && metalDoor.transform.position.y < doorLimit)
metalDoor.transform.position += Vector3.up * doorSpeed * Time.deltaTime;
Answer by KTVX94 · Jul 31, 2017 at 10:34 PM
Found the issue, I had the same script dragged to both the intended game object and one of its children accidentally. The parent was working and the errors were sent from the child.
Your answer
Follow this Question
Related Questions
UnassignedReferenceException: The variable enemy of EnemiesSpawner has not been assigned 0 Answers
Variable has been assigned but has UnassignedReferenceExcecption 1 Answer
Unassigned ReferenceException variable with Button? 0 Answers
UnassignedReferenceException when the Variable is assigned to my GameObject 0 Answers
Unassigned Reference Exception although it is assigned 0 Answers