- Home /
GameObject.Find not working
[SerializeField]
GameObject player;
void Awake()
{
player = GameObject.Find("Game/Player/Chest");
}
so the problem is this is not working and I don't know why and any help is much appreciated.
(Note: The gameobject that this script is in is Disabled but the gameobject that im finding is not)
Answer by LowTierCoder · May 15, 2020 at 04:52 PM
player = transform.Find("/Game/Player/Chest").gameObject;
I found a way to do it and this is how I did it. I just changed it to this.
Answer by Saiansh2525 · May 15, 2020 at 04:35 PM
I think you need to put another slash before the Game in the string.`player = GameObject.FInd("/Game/Player/Chest");`
It is still not working, actually that was the first thing I did but it's still not working. Thx for the help tho.
Answer by diwang · May 15, 2020 at 04:55 PM
https://answers.unity.com/questions/1374581/start-and-awake-not-called-on-monobehaviour.html
https://forum.unity.com/threads/gameobject-setactive-vs-enabled.195658/
https://forum.unity.com/threads/is-awake-no-longer-called-on-inactive-objects.461394/
First of all , the term "disabled/enabled" is only for component , for gameobject it's called "active/inactive" , Awake() will not get called on inactive gameobject , Awake() is still get called in disabled script as long as the gameobject is active .
So the problem here is that it's not the GameObject.Find that isn't working , but the Awake() itself never get called since the gameobject is inactive.
Answer by N-8-D-e-v · May 15, 2020 at 10:33 PM
Don't use find, it isn't very reliable, try just getting a reference from the inspector using
public GameObject player;
then drag and drop