0

so... I am trying to make an animation appear when you beat the level. this will be accomplished by activating the object when the level ends, however I got an error when the level ended.

this is the error

Object reference not set to an instance of an object

so I start it out like this

void Awake()
{
    GameObject endan = GameObject.Find("Levelthing");
    endan.SetActive(false);

}

I removed unimportant code in the awake function, this code works.

the level ends after a certain amount of time has passed

IEnumerator Counts()
{
    Debug.Log("Counting");
    yield return new WaitForSeconds(264);
    Debug.Log("Level Complete");
    GameObject eendan = GameObject.Find("Levelthing");
    eendan.SetActive(true);

}

after researching the error I found that it meant that it meant the reference was not found. to "eendan" (my variables have weird names) even though I had referenced it the line above.

  • The object no longer exists to be found in your second snippet. So you need to identify the point when that object was removed. – Peter Dongan Apr 12 '20 at 04:15
  • @NeutralHandle so I watched the entire level while looking at the hierarchy: the object is never removed. it's literately just text. also manually activating it at the end of the level works. – CooCoo 333 Apr 12 '20 at 04:22
  • @NeutralHandle Oh wait I think I read somewhere that not activated objects can not be found using .Find – CooCoo 333 Apr 12 '20 at 04:27

0 Answers0