NullReference Exeption thrown even when checked against
Hi,
I know this question has been asked before but looking at the answers I couldn't understand what the issue is. Attached is the image of the code in question. I'm checking if something is null or not and that check is throwing a NullReference Exception.
Can someone help get rid of this error?
Thanks!
Answer by OneEyeMaker · Nov 27, 2016 at 02:50 PM
I guess, that
transform.Find(...)
returns null. Consequently,
transform.Find(...).gameObject
throws NullReference Exception.
Yeah, that was the issue, thanks. The problem was fixed by editing the if statement to: if(transform.Find("$$anonymous$$achinegun(Clone)/$$anonymous$$uzzle") != null)
Answer by obses · Nov 27, 2016 at 02:50 PM
I believe that unity has a problem with finding that gameObject you are looking for, therefore it is not able to to chcek if it is null or not. Unity not knows which object to compare - so it throws NullReference Exception...
Your answer
Follow this Question
Related Questions
null reference exception help 1 Answer
NullReferenceException: Object reference not set to an instance of an object 1 Answer
Input Working in Editor but not in Build 0 Answers
NullReferenceException after build 1 Answer
Need some help with networking, Object reference not set to an instance of an object. 0 Answers