Search Unity

Easy Way To "reload" Active World?

Discussion in 'Entity Component System' started by Bas-Smit, Apr 10, 2019.

  1. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    Previously I would often reload the current scene to restart whatever happens in that scene, is there any way to do something similar for the active world? I can do

    World.Active.Dispose();


    but I havent found a way to reload the world as it happens on startup?
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    There is a DisposeAllWorlds method, but worlds are designed to have a game scope so I don't think I would do that even if you can.

    What I do is the systems that need it implement an interface with OnActivate(Scope scope)/OnDeactivate(Scope scope) methods. I use that to manage state of various scopes which could be a scene unload/load or something else.

    You could also tag entities with a scope component of some type to go along with that, run a job to destroy all entities of the scope in question.
     
    Bas-Smit likes this.
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Generally you do that by unloading the scene and all entities that are in the world that were created from code.

    Systems should not carry state, so the concept of destroying a whole world to reset it doesn't make sense.
     
    Bas-Smit likes this.