Preventing unused objects from being loaded in a scene?

I’m making a space shooting game where each “galaxy” has its own background & enemies. Now, if I have controllers where a prefab of every possible background, enemy, projectile, audio & fx is stored, but only X amount of them are actually used (based on the “galaxy” selection), what is the best way for loading a scene where only the objects I want to use are taking up memory?

It’s my understanding that inactive game objects in the scene and objects in the scene that are referencing prefabs are still being loaded, the sprites and everything, correct? Is the only way around this having a scene for each “galaxy” or is there a way for a controller to create everything from all possible choices without any unnecessary overhead?

Yes and No.
Objects that are in the scene but are inactive are loaded.
However if you’re referencing a prefab, it is not loaded into the scene, and will be loaded when you instantiate it. (as far as I’m aware)

You can spawn items you’re going to need ahead of time. Basically, implement a pool for objects, spawn as many as you want in advance and make them inactive. You can do that during the level load.

You can also use additive scene loading, if that’s what you prefer. Personally I find prefabs more comfortable to work with than additive scenes.

2 Likes