How to remove all entities?

Hello Paul!

Thanks again for the Zay-ES. I’m using it. And it rocks.

I have a question: how to remove all entities from the EntityData? For example, i want to reload a level.
I did not find a method like “entityData.removeAll()” or “entityData.clear()”.

At present i can only find entities by a component and remove them. but what if i need just to remove them all without any component search?

I also found “entityData.close()” method but i dunno know what it does.

Thanks.

@mifth said: Hello Paul!

Thanks again for the Zay-ES. I’m using it. And it rocks.

I have a question: how to remove all entities from the EntityData? For example, i want to reload a level.
I did not find a method like “entityData.removeAll()” or “entityData.clear()”.

At present i can only find entities by a component and remove them. but what if i need just to remove them all without any component search?

I also found “entityData.close()” method but i dunno know what it does.

Thanks.

There is no way to do this… and it might be a bit dangerous even if you could. Even in your use-case, you might have entities that are not associated with the level (player, score, etc.) that should not be cleared. Also some of a game’s systems may not react well to having everything just disappear.

If you have game entities associated with your level then you can always remove them yourself… and can do it in a clean way that won’t break any system to system ordering the game might be relying on or remove things that should stick around, etc…

See, on the one hand, removing all entities really only makes sense for an in-memory ES. On the other hand, you probably want to reset the systems (and their EntitySets) at the same time… in which case, just forget the old ES and create a new instance. And if that’s no good, then you really had some dependency that makes removing all of the entities a bad idea.

EntityData.close() is for shutting down a particular ES instance which may have things it needs to close (like database connections or files or whatever).

@pspeed said: There is no way to do this... and it might be a bit dangerous even if you could. Even in your use-case, you might have entities that are not associated with the level (player, score, etc.) that should not be cleared. Also some of a game's systems may not react well to having everything just disappear.

If you have game entities associated with your level then you can always remove them yourself… and can do it in a clean way that won’t break any system to system ordering the game might be relying on or remove things that should stick around, etc…

See, on the one hand, removing all entities really only makes sense for an in-memory ES. On the other hand, you probably want to reset the systems (and their EntitySets) at the same time… in which case, just forget the old ES and create a new instance. And if that’s no good, then you really had some dependency that makes removing all of the entities a bad idea.

EntityData.close() is for shutting down a particular ES instance which may have things it needs to close (like database connections or files or whatever).

I use ES only for levels. No any other usecases for it. If do so, will it be ok?
[java]
entityData.close();
entityData = new DefaultEntityData();
[/java]

Or the best way is to remove entities by a inGameComponent?

@mifth said: I use ES only for levels. No any other usecases for it. If do so, will it be ok? [java] entityData.close(); entityData = new DefaultEntityData(); [/java]

Or the best way is to remove entities by a inGameComponent?

That’s weird that your player is not an entity or that it doesn’t keep stuff from level to level… but I suppose it’s possible.

Yeah, what you have is fine if you are then recreating all of your EntitySet references and so on. Which you probably should be anyway since all of your old code is likely to get confused if you could remove all entities.

@pspeed said: That's weird that your player is not an entity or that it doesn't keep stuff from level to level... but I suppose it's possible.

Yeah, what you have is fine if you are then recreating all of your EntitySet references and so on. Which you probably should be anyway since all of your old code is likely to get confused if you could remove all entities.

Thanks a lot!