Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question ECS Restart System

Discussion in 'Entity Component System' started by jose_san, Jun 30, 2023.

  1. jose_san

    jose_san

    Joined:
    Jun 13, 2023
    Posts:
    2
    Currently working on a game with ECS Dots using the 1.0.10 version. After the the player is destroyed and is shown the Game Over screen I would like to destroy all entities so if the player restarts the game they are back at it without reloading the scene.

    Anyone have any thoughts or have gone through the same and found a way?

    Some ideas I have thought and haven't tried:
    • Reload Scene (last resort if there isn't a way)
    • Add a component tag to all entities that tags it to destroy
     
  2. DatCong

    DatCong

    Joined:
    Nov 5, 2020
    Posts:
    77
    Reload scene should resolve most problem. why reload scene dont suit for u?
     
  3. FaithlessOne

    FaithlessOne

    Joined:
    Jun 19, 2017
    Posts:
    257
    Another way would be destroying the ECS world and recreating it. But this requires a customized world setup process in your game.
     
  4. jose_san

    jose_san

    Joined:
    Jun 13, 2023
    Posts:
    2
    I decided to go with the second bullet point. I tagged entities to be deleted which works for me at the moment.
     
  5. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    908
    I evaluated a bunch of options. There are a lot after all
    - reloading scene
    - recreating world
    - delete specific entities
    - reloading subscene

    From all options, reloading the subscene was the best. The reason it's the best option is that instantiated entity prefabs live in the subscene. So unloading a subscene also destroys any entities with it. Now it's just a matter of splitting into the right subscenes, so prefabs are grouped together and so you can unload and load the minimal amount possible.
    It's FAST and requires very little code and it's just a matter of referencing the subscenes and then unload/load the guids.