unity – Why the target variable can’t find the object name “Base”?


Awake() gets called immediately as soon as the object has spawned/loaded. It’s almost like a constructor, in that it will finish before a call to Instantiate() returns the newly spawned object.

That means that anything else that’s being spawned in the same/subsequent pass is not necessarily in existence yet.

In this case, it’s likely that your first scene loads and calls Awake() on all its objects before the second scene has finished loading, so the object simply doesn’t exist yet to be found.

By moving your search to Start(), you delay it until just before the first Update() tick, giving time for the rest of the scene(s) to finish loading so their objects are ready for you to find.



Source link

More To Explore

Share on facebook
Share on twitter
Share on linkedin
Share on email