Scripting for scene-related events, such as for when the scene first loads, etc?

Hi folks,

I’m new to Unity and am shooting for a basic learning project in which I want to programatically instantiate some prefabs. That’s my entire goal, at the moment.

Having done some basic game dev in other lower level environments in the past, I’m thinking in terms of like a main game loop, etc. At the moment, I’m not quite sure what Unity-based games main game loop is.

So, I’m just looking for some pointers on how to do things like “when this scene loads, start spawning minions”, “keep track of minions spawned”, etc.

Is there an appropriate way to do scripting for something like the scene, so that immedietly as the scene loads I can instantiate some prefabs?

Thanks!

just put the script on a object in the scene, and have it do all the spawning and keeping track of what it created in the Start() method

the main loop is pretty hidden away from the user, your are best to embrace components. Each component has functions that get executed when they are created, enabled, disabled and destroyed as well as methods get called every frame, or physics step.

You can also use the SceneManager.sceneLoaded event to get a callback when a scene has loaded.

But what @passerbycmc suggested is probably the best solution for what you want to do!

-sam