SIGN IN SIGN UP
bevyengine / bevy UNCLAIMED

A refreshingly simple data-driven game engine built in Rust

0 0 59 Rust

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

# Objective

The changes introduced in
- #24174 

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

- [x] `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
- [x] Run examples
- [x] Benchmark (uh oh, i'm a bit afraid of those...)

<!--
- Are there any parts that need more testing?
- How can other people (reviewers) test your changes? Is there anything
specific they need to know?
- If relevant, what platforms did you test these changes on, and are
there any important ones you can't test?
-->
L
laund committed
3ef25d87f6148391bea419fb6b17a73b68700181
Parent: 69fd54a
Committed by GitHub <noreply@github.com> on 5/31/2026, 5:05:34 PM