Help: (Typing Game) Missing Reference Exception

Updated on May 31, 2018 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
4 on May 29, 2018

hi.. i followed your video tutorial about typing game and it’s really nice. but when i destroy word prefab when it get into specific y position like having boundaries, and i’m typing gives me an error “missing reference” because it does not remove in the list.. how can i remove it from the list and destroy it at the same time when it hits in the given y position. i hope you can help me. thanks in advance.     

  • Liked by
Reply
3 on May 29, 2018

store a reference to it from the list, remove it from the list, then destroy the reference you saved.

GameObject word = wordList[index];
wordList.Remove(word);
Destory(word);
on May 30, 2018

thanks bro, i manage to remove it in the list and destroy word prefab at the same time. but it didn’t fix the error. i think the problem is occur when the active word i’m typing is destroy and still trying to access it.

 public void RemoveLetter()
{
txt.text = txt.text.Remove(0, 1);
txt.color = Color.red;
}

i think i have to switch to another word if the word i’m typing is destroyed. 

on May 30, 2018

Yes, all references to the word should be reset to something else, or null, before destroying it.

 

on May 31, 2018

thanks a lot bro.. works like a charm! 

Show more replies
  • Liked by
Reply
Cancel