Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDTK entity problem. #303

Open
Gavolot opened this issue Feb 22, 2024 · 1 comment
Open

LDTK entity problem. #303

Gavolot opened this issue Feb 22, 2024 · 1 comment

Comments

@Gavolot
Copy link

Gavolot commented Feb 22, 2024

Perhaps I don’t understand something, but I have such strange seemingly problems:

  1. I have no way of knowing to which level the entities “registered in LDTK” belong. And I really need this in order to somehow delete them when changing levels or exiting. I can enter a level once and delete it, but when I enter it a second time, it turns out I have to load the entire ldtk world, and at the same time somehow save what level we are moving to... It looks extremely strange.

  2. Is it really true that all entities of all levels are created at once and only 1 time?

@Trouv
Copy link
Owner

Trouv commented Mar 17, 2024

Sorry it took me some time to get to this issue.

I have no way of knowing to which level the entities “registered in LDTK” belong. And I really need this in order to somehow delete them when changing levels or exiting. I can enter a level once and delete it, but when I enter it a second time, it turns out I have to load the entire ldtk world, and at the same time somehow save what level we are moving to... It looks extremely strange.

So, once an entity is spawned via the registration system, it will be a grand-child of the level entity in bevy's transform hierarchy. You can read more about the hierarchy of the LDtk world the plugin follows in this chapter: https://trouv.github.io/bevy_ecs_ldtk/v0.9.0/explanation/anatomy-of-the-world.html

So, actually, when a level despawns (recursively), it should despawn all of its children, which includes all of its entities. Is that not what you're observing? How are you despawning levels, are you using the level selection mechanisms provided by the plugin?

The exception to this is entities that you give the Worldly component, which will make it a child of the world entity rather than the level entity. The purpose of this component is to make it so worldly entities don't despawn when a level despawns, and also don't doubly-spawn if a level is is despawned/respawned. It's intended for entities that persist between levels, like a player.

Is it really true that all entities of all levels are created at once and only 1 time?

This is not entirely correct. It is true that all entities within a level are spawned at once. However, it's not necessarily the case that all levels are spawned at once - only the newly-selected ones in the previous update.

Also, entities are spawned only once when the level is spawned, but if that level is despawned/respawned then those entities will be despawned/respawned too. The exception to this, again, is entities given the Worldly component.

I hope this clears things up, but I'm not 100% sure I understood your questions completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants