Skip to content

State preserving template building #212

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Constanze3
Copy link

@Constanze3 Constanze3 commented Jun 15, 2025

Summary

This change introduces a new approach to template building where components of entities that already exist (based on their anchor) are preserved, unless they are not part of the template in which case they will be despawned.

This functionality can be accessed by calling build_preserving or build_children_preserving on EntityCommands.

I also added a few tests to verify this behavior.

Why?

Currently, when building templates, the entire component set of an entity is overwritten by the template, regardless of whether the entity already exists. This behavior is problematic for UI elements that rely on persistent state, as it resets the state of child components.

Example

Consider a scenario with expansion tiles (foldable UI elements) in the scene tree. If some tiles are folded and an entity is deleted, the scene tree will need to be rebuilt. With the current approach, rebuilding the scene results in the template overwriting the state of the expansion tiles, causing them to unfold and effectively discarding the user's prior state.

@Constanze3 Constanze3 changed the title State perserving template building State preserving template building Jun 15, 2025
@alice-i-cecile alice-i-cecile requested review from janhohenheim and BD103 and removed request for BD103 and janhohenheim June 16, 2025 02:49
@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged A-Scenes The scene format, and serialization/deserialization to it. labels Jun 16, 2025
@Constanze3
Copy link
Author

I think the implementation is fine. I’ve read through the code several times and I’m already using it in my scene tree prototype on my fork. I’ll add a few small tests later.

@Constanze3 Constanze3 marked this pull request as ready for review June 16, 2025 09:14
@janhohenheim janhohenheim added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Scenes The scene format, and serialization/deserialization to it. S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants