- Home /
Prevent Object From Loading
Hello everybody,
I worked my way through Unity's Execution Order at http://unity3d.com/support/documentation/Manual/Execution%20Order.html and wondered whether there is a possibility of preventing a given object from loading at the start of a scene.
To be more specific: My game requires scene transitions that return to previous visited scenes again and again. Some of these objects might have been destroyed in between, but would be loaded again as soon as the player returns. Our idea is to save the game state in form of conditions to a specific Manager object that has DontDestroyOnLoad called at the beginning of the game.
Next step would be to destroy these objects in Awake if these conditions hold true, but I'd prefer not even loading them... Any ideas?
Answer by syclamoth · Oct 04, 2011 at 01:37 PM
Ususally for this kind of thing, I make an empty "void" scene which only contains the important stuff which shouldn't get destroyed between levels (player info, game engine stuff), load it first, and then immediately load the actual scenes after setting 'DontDestroyOnLoad' for all my game engine stuff. I then never go back to the initial scene unless I want to do a full reset, in which case I manually delete the game engine bits, and reload from level 0.
Yes, so do we. But how do I prevent parts of the "actual scenes" from being loaded? I'll add an example:
We have a scene A that contains the main character and his dog. His dog dies. The main character moves on to scene B. Having done some stuff there, he returns to scene A and his dog would be there again, because it was part of the Unity scene file.
In your important game-engine stuff, have a variable with 'isDogDead', which your game queries when it would spawn a dog. To get around this stuff, I always instantiate prefabs for players etc. when I load my levels!
Answer by npruehs · Oct 05, 2011 at 09:12 AM
Alright - but this approach has another drawback: Desingers and level artists are unable to check their work without starting the game over and over again...
Anyway, thanks for the answers! :)
This is exactly the problem i'm having. I would like an answer too.
Have the object in the scene hierarchy, but destroy on load if it should not be there.
Yes, but this requires that they have been loaded into the scene in first place, which takes time, and that is exactly what we're trying to avoid.
Otherwise, there is no point in having a load scene in the first place.
Oh right, I see... perhaps this will help: http://docs.unity3d.com/ScriptReference/Application-isEditor.html
e.g. Instantiate depending on if the object should be loaded, or if in the editor just override as you wish.
Shove the stuff in a prefab. When running the game, your first scene as per syclamoth's answer (I call that a 'bootstrap' scene) instantiates the prefab. Designers and level artists can check (and work on) their work in Edit mode, in any scene, by just dragging the prefab in, editing it, and applying changes.
Your answer
Follow this Question
Related Questions
heavy scene loading 1 Answer
pre-load multiple scenes but only activate one 0 Answers
Addressable for Oculus Go 2 Answers
Save & Load Game question 3 Answers