#Clean up all created entities

1 messages · Page 1 of 1 (latest)

gritty locust
#

This seems like a very basic question so I feel like there must be something I'm missing, but...

I have a very simple game structure where I want to go from the main menu (no ECS) into the game scene, then back to the main menu. It seems obvious that when I go back to the main menu I need to clean up all the entities in the World, but I can't see a nice way to do that.

EntityManager.DestroyEntity(entityManager.UniversalQuery) or EntityManager.DestroyAndResetAllEntities on the DefaultGameObjectInjectionWorld almost work, but they also kill the Physics singletons and other default entities.

Should I be creating my own World if I want to be able to go in and out of it, or is there a way to remove only the entities that are created as part of the game scene? Or am I thinking about this entirely wrong?

errant jetty
#

you just need to keep track of all loaded entities

#

via subscenes

#

for example

#

all subscenes you load = just unload them in the end

leaden jetty
#

As you have figured out deleting all entities is a bad idea as you'll destroy all the singletons as well

#

I'm personally a fan of just creating and destroying worlds as you enter and leave the menu as it cleans up all your memory

#

But you can just keep the world around forever and open and close subscenes instead of you prefer