Function called from preloader script doesn't change parent of gameobject (in the second scene)

If line 8 relies on something being present from the scene load in line 7 (in GameController), it won’t be: scenes are loaded at the end of frame and would never be available until the next frame, at the very earliest.

You can trivially make void Start() into a coroutine by declaring it to return an IEnumerator, then put a while loop (with a yield return null; in it!!!) to wait until the scene loads and you find the “Trains” object, then proceed.

Obviously you would need to interlock other things from going forward until that happens, such as things dependent on the trainAndPlayer quantity being non-null.

1 Like