I’m really new to Unity so I apologize if this is obvious…
I have a script made to procedurally populate a scene with objects, but I’m not sure where I can set this to run because the scene has basically nothing but the camera at the start.
I’m really new to Unity so I apologize if this is obvious…
I have a script made to procedurally populate a scene with objects, but I’m not sure where I can set this to run because the scene has basically nothing but the camera at the start.
You can put it in any GameObject, so put the script in the Main Camera, it will run when the scene loads!
Make a class derived from MonoBehaviour.
Attach that class to an object in the scene.
Put your code in your class’s Awake() or Start() methods.
You can decorate a method on any class with RuntimeInitializeOnLoadMethod. There are multiple optional modes, but the plain or AfterSceneLoad loadtype attribute is probably the one for you.
There is also a SceneManager.onSceneLoaded callback you can add a listener to, but that would have to be on an object created at a different time, and that is set to DontDestroyOnLoad.
You can also use Awake on the relevant objects, but you may have to mess with script execution order. Awake does run before the first frame and it seems like the most straightforward way.