Skip to content

bsn: fix accidental scene entity deduplication due to name references#24402

Open
laundmo wants to merge 5 commits into
bevyengine:mainfrom
laundmo:bsn-fix-unique-entity-reference-id
Open

bsn: fix accidental scene entity deduplication due to name references#24402
laundmo wants to merge 5 commits into
bevyengine:mainfrom
laundmo:bsn-fix-unique-entity-reference-id

Conversation

@laundmo
Copy link
Copy Markdown
Contributor

@laundmo laundmo commented May 23, 2026

Objective

The changes introduced in

only used the exact macro invocation file/line/column plus a per-macro name id from a counter as the key for SceneEntityReference.

That means if the same bsn macro with a fixed entity name is called multiple times it will only spawn a single entity instead of however often it was called. This is clearly buggy behaviour.

Solution

This PR introduces a runtime call-counter which is only added if named entity references are used, and is incremented with each call to the macro. This is then used as part of the key, making sure entities from different calls to the generated code are treated as distinct.

It also vastly improves the handling of #{expr} names, which were previously incompletely handled.

Testing

  • cargo test in bevy_scene with new test for this issue
  • Test with the code of the original reporter, @chyrr. on discord and perhaps @ashikun who ran into this as well
  • Run examples
  • Benchmark (uh oh, i'm a bit afraid of those...)

@laundmo laundmo added A-ECS Entities, components, systems, and events A-Scenes Composing and serializing ECS objects D-Domain-Expert Requires deep knowledge in a given domain S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 23, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in ECS May 23, 2026
@laundmo laundmo requested a review from cart May 23, 2026 01:09
@laundmo laundmo added this to the 0.19 milestone May 23, 2026
@laundmo laundmo added the C-Bug An unexpected or incorrect behavior label May 23, 2026
@laundmo
Copy link
Copy Markdown
Contributor Author

laundmo commented May 23, 2026

CI failures: i can fix the typo, but the other one is a failure in bevy_reflect which this PR doesn't touch

@laundmo laundmo changed the title fix accidental entity deduplication due to name references bsn: fix accidental scene entity deduplication due to name references May 23, 2026
Comment thread crates/bevy_ecs/src/template.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events A-Scenes Composing and serializing ECS objects C-Bug An unexpected or incorrect behavior D-Domain-Expert Requires deep knowledge in a given domain S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

2 participants