[SOLVED] How to load a new level or reload a level

I use Zay-Es for my platformer. Everything works out fine, but now I want to load the next level or even reload the existing level. All the debris and dead bodies and stuff I have in existing levels should now be removed.
Is there an easy way to do that? Kind reset or something. How do you guys normally solve that?

In my case (online multiplayer), I have an entity with Scene and Level components for each scene.

The Scene component has the width and height of the world used to create physic space and nav space.
The Level component indicates the level (1,2,3,…) of the scene.

Then in SpawnPosition component, I have a field sceneId points to the entity id of the scene the body is inside it.

private EntityId sceneId;

Now when I want to remove a scene, I find all bodies which their SpawnPosition points to that scene id and remove them too.

In my case, the scene state and all bodies inside the scene are persisted into the database using Zay-ES SqlEntityData.

For reloading the scene, I use anOnline component (this component is non-persistent) to reload the scene when team members are connected. So when team members leave the game I remove the Online component from the scene and all bodies inside the scene so they are cleared from the game systems and when team reconnected again I re-add the Online component to the scene and all bodies inside the scene.

To load an initial scene is no problem, I can just construct it based on a file. My problem is that all debris like blood, body parts, brick fragments etc. are also entity ids. So when I got you correctly you would have a scene entity and everything inside that scene does have a link component on your scene, so you can remove it (or alternatively store into a DB if you want to reconstruct the scene if you enter it again)? Or do you just not care about the amount of entities at all?

Hmmm the more I think about it the more questions I have :smiley: when I switch the level/room and re-enter it later, I still want the debris in place. But I also want to fresh load a level and then I want my debris gone. Everything is an entity actually.

I don’t know how common my request is, maybe it is just something special in my case?

Yep,
Note the reason I added the scene Id into SpawnPosition instead of using a Link component is because that scene id is a feature of position.

and I like SpawnPosition, I think I will rename my Position to SpawnPosition and my PropagatedPosition (changed by dyn4j) back to Position :smiley:

And for each level I have a level prefab (blueprint) which is a JSON file and I use it to create and initialize a fresh level.

For that I have a very simple text file :slight_smile: my problem was more about “go rid of” the entities which do not belong to the level but are just debris of the battle :slight_smile:
But I think there is no easy way around the fact that I have to keep track of all entities with in a level one way or the other. I could even go with a tag for all the stuff in a level and have a system to remove them all from ECS. I thought there are some kind of best practice, I guess keep track is the best practice here then.
Thanks for the insights, helped already a big deal!

1 Like