'Unity Can I use yield return new WaitUntil(() => GameObject.Find("xx")) in IEnumerator Start()?
I want to stop the Code in my Script until it finds a GameObject and then continue.
I tried it in my Start Method with the following Code :
yield return new WaitUntil(() => GameObject.Find("Ball1"));
GameObject.Instantiate ...
But this doesn't work (Never Instantiates my GameObject)
Does anyone know what Im doing wrong or have another idea?
Solution 1:[1]
First you shouldn't use GameObject.Find each frame (that's what WaitUntil does according to the unity docs) Secondly, about why it isn't working, GameObject.Find returns null if the specifies gameobject isn't found else it returns the reference to the gameobject. Try returning true and false for that and it might work So
WaitUntil(() => GameObject.Find("name") != null)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jens Piegsa |