- Home /
The question is answered, right answer was accepted
transform find with tags always return null
Hi, I know that my question has been asked by other people, but I have tried to read those post but still can't solve my problem so I decided to post my own question. I tried to get the Animator components from a a child of a child using the code on the attached image. But it always return null reference object reference not set to an object bla bla... I already have the workaround using the commented code (ignore the wrong variable name) but I still want to know why I got those errors since I am still learning Unity. Thank you
I see, I thought that Find was supposed to find Tags turn out it find the name of the gameobject ins$$anonymous$$d. Thanks I finally can have peace in $$anonymous$$d
Answer by metalted · Apr 03, 2019 at 03:37 PM
transform.Find uses a string to find a child. The LookRoot string is fine but the FPCamera string doesnt have a space in it while your gameobject does.
To debug this, try spreading it out. First get the lookroot object, debug the transform to see if you found it. Then get the fpcamera from that and debug again. In that case it would return null. Then the problem is in the second Find().
Also spreading things out makes it more readable
Follow this Question
Related Questions
transform.Find always returns null 1 Answer
How do i find a bone on my character within a script? 2 Answers
Transform.Find(string) no longer finds grandchild? 6 Answers
GameObject.Find("something")..how to use with transform,audiosource and texture ? 1 Answer
C# The call is ambiguous between the following methods or properties 1 Answer