Why is Find() not working?
I have used the line GameObject player = GameObject.Find("Player"); but it keeps returning null, I have also tried a couple other ways of doing this but none work I just keep getting null.,I have used the code GameObject player = GameObject.Find("Player"); although it keeps returning null, I have also tried a few different ways of doing this.
Thanks for the help!
Do you have an active GameObject with that name, at the time you make the call?
Yes it is active in the hierarchy with the same name "Player"
Can you prove this? I suspect that you are wrong, but even if you are right, the process of trying to prove it might reveal what's going on.
Answer by $$anonymous$$ · Jan 27, 2018 at 05:49 PM
Most likely, if it is returning null, then no object exists with the name "Player".
On a script of your player object, put this in Start to make sure that the player name is what you think it is.
Debug.log(gameObject.name):
Sometimes if you do something such as spawn the player in, then the name will change to something like "Player (clone)".
Have you tried finding the player using tags ins$$anonymous$$d?
Player = GameObject.FindWithTag("Player");
Another trick is to put Debug.Logs in OnEnable() and OnDisable() functions, to help you to work out whether or not the object is active at the time of the Find call.
If your player object is part of the scene's initial state, you can link the player to one of your scripts in the inspector ins$$anonymous$$d of using a Find method
Answer by victorbisaev · Jan 28, 2018 at 10:42 PM
Check "Player" GameObject is active at the moment "Find" is performed.
Your answer