Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Best Practices] How to change scene

Discussion in 'Project Tiny' started by Adrian-Anta, Mar 26, 2019.

  1. Adrian-Anta

    Adrian-Anta

    Joined:
    Oct 26, 2012
    Posts:
    35
    Hi, I'm working on a spaceship shooter and now I'm implementing the screen states. I've realized that I want to destroy all gameplay entities when I move to the main menu. The thing is that I was instancing entities as entity groups in the root and now I need to figure out the best way to find and destroy the right instances.

    I've come up with two ideas:
    - Parent every instance in the gameplay screen to the same parent and then destroy itself and all children. I don't like this approach much.
    - Add a tag component per screen to each entity group. When I move to the main menu I iterate through all entities with the gameplay component, for example, and I destroy them. If you reuse the same entity group in many screens maybe the component should have a screenEnum[] instead of being just a tag.

    What's the right way to do this? Would you like to share your own solution?

    Thank you in advance.
     
    Last edited: Mar 26, 2019
  2. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    129
    EntityGroups already basically function like a tag after instantiating.

    You can call
    ut.EntityGroup.destroyAll(this.world, "game.myEntityGroupName");
    and it remove all entities from just that group.
     
    Adrian-Anta likes this.