- Home /
Confusion about DontDestroyOnLoad and very large scenes...
Say you have two scenes, #11 and #12, with huge load time (say 30 seconds load time).
scene 11 .. contains an enormous object "Island", and a few other things
scene 12 .. contains the identical enormous object "island", and a few other things
Say you've just loaded and used scene #11. You now want to change to scene #12.
it seems ridiculous to re-load the "island" object again. Is this exactly what DontDestroyOnLoad does?
My question: if inside #11 you set "island" (and that is inside #11) as DontDestroyOnLoad, then, once #12 loads,
in fact is the island in #12 now the "same" island as we just had in #11?
is that exactly correct? Does anyone know?
Follow-up question: once #12 is loaded, does "island" return to it's original state (as when #11 first loaded)? Or, is it "unchanged" from the moment of changeover -- ie all the variables and so on have whatever values they have when you called for the loading of #12.
I realise this question is in the lame "couldn't you just try it?" category :)
By the way, I completely understand that you can just load the island, and then drop in the various "other stuff" to create scenes like 11 and 12. But it is incredibly better workflow if the teams can just work on their own scenes. I absolutely understand how to do it "manually", I am looking for an answer to the question written above, if anyone knows, thanks.
Tricky follow-up question: Say scene #12 does NOT happen to include the "island". (i.e., you have pointlessly, perhaps accidentally, marked the "island" as DontDestroyOnLoad in #11 .. but in fact you are not even using it in #12.) In fact, in that case, what the hell happens to the "island"? Does it just hang around in memory - but not part of scene #12 currently playing? Or does it force itself in to scene #12 (presumably at the same transform position) ... or what???
Final follow-up question Do you have to do anything in scene #12, to let scene 12 know that it should "not load" "island", since island will already be there? Or, will in fact scene #12 (completely pointlessly) load "island" again anyway? Or in fact, do you have to not include "island" in scene #12? Or what??
if anyone can answer the four questions, THANK YOU !!!
Answer by syclamoth · Oct 11, 2011 at 12:30 PM
When you load the scene, Unity does not know that the 'huge island' is in fact identical to the one already in the scene- you will end up with two instances of the same huge object! The load times will remain. There will be a 'new' island, which is in 'mint condition', and in the same spot as your old island.
I think the main answer to all of your question is that all 'DontDestroyOnLoad' does is prevent Unity from deleting those specific objects upon scene loading. If your new scene doesn't have the island in it, the island will stay, (and probably look pretty weird in the middle of your new scene).
In my opinion, you should have the island in one scene, which gets loaded first, and then use LoadLevelAdditively to put in scenes with all the new content in it. If you have your island duplicated, that's how it will end up- Unity has no way of knowing that you don't want two of that huge island in your game! (it's kind of stupid like that).
Doing it that way has the disadvantage that each 'subscene' doesn't get to see the island when it's getting assembled (unless you do something clever like put a super-low-res 'proxy' island in, which gets deleted upon scene load in an Awake() script). But the advantage is that you only have to load large assets once, and only delete them when you want to move on to a totally new scene using LoadLevel (not additively).
@Sycla, thanks a million for the clear answer. Awesome. Regarding what you said about workflow: Would this work: in scene 12, have the full island there during work in progress. When you build, simply, just deactivate the island in scene 12. IE simply uncheck the small check-box at the extreme top left of the Inspector. If you have that checkbox "off" -- it does not even load as an asset .... is that correct? Alternately is there some other programmatic way to NOT load an object of a scene? (perhaps a whole other question there!) Thanks again!!
As far as I can tell, there's no way of stopping an object from being loaded. You have to load the objects before you can act on them! I'm pretty sure deactivating it before build would work the way you want it to- have a look at build pipeline scripting if you want to do it automatically! (I don't know anything about that, other than that it is possible...). Test it all, of course- this isn't really something I've ever done, (the humungous single asset thing, that is, I've done plenty of level loading), so you'd have to test it all before committing to anything.
Having thought about it a bit more, I'm convinced that having a super-low-detail island to work on (which gets deleted upon level load or before build, whatever you can do) would have to be the best in terms of work-flow. As long as your level designers don't need perfect detail in order to do their work.
Good one, thanks! You know, a very simple pipeline solution is, simply, just $$anonymous$$ETE the island in #12 before you build. that works perfectly. so long as it's easy to put it back in again for the next round of development (normalise the coords using a holder to 000). That would work fine. I'm gonna go check if it ACTUALLY LOADS an object which is $$anonymous$$AR$$anonymous$$ED INACTIVE -- I fear it probably does. Thanks again!