-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesA "normal" level of difficulty; suitable for simple features or challenging fixesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!X-ControversialThere is active debate or serious implications around merging this PRThere is active debate or serious implications around merging this PR
Milestone
Description
Bevy version
v0.16.1
What you did
Inserted the children! macro on an entity that had existing children.
What went wrong
Instead of appending the new children, the existing ones got overridden.
Minimal repro
I wanted to cover a variety of scenarios but the override seems to be consistent.
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(
Startup,
(
spawn_entities,
print_children,
patch_entity_f,
print_children,
)
.chain(),
)
.run();
}
#[derive(Resource)]
struct EntityF(Entity);
fn spawn_entities(mut commands: Commands) {
commands.spawn((Name::new("Entity A"), children![(), ()]));
commands
.spawn((Name::new("Entity B"), children![()]))
.insert(children![()]);
commands
.spawn(Name::new("Entity C"))
.insert(children![()])
.insert(children![()]);
commands
.spawn(Name::new("Entity D"))
.with_child(())
.with_child(());
commands
.spawn(Name::new("Entity E"))
.with_child(())
.with_child(())
.insert(children![]);
let entity_f = commands
.spawn(Name::new("Entity F"))
.with_child(())
.with_child(())
.id();
commands.insert_resource(EntityF(entity_f));
}
fn patch_entity_f(entity_f: Res<EntityF>, mut commands: Commands) {
commands.entity(entity_f.0).insert(children![]);
}
fn print_children(entities: Query<(&Name, Option<&Children>)>) {
for (name, children) in &entities {
let children_count = children.map(Children::len).unwrap_or(0);
println!("{} has {} children", name, children_count);
}
}The output:
Entity A has 2 children
Entity B has 1 children
Entity C has 1 children
Entity D has 2 children
Entity E has 0 children
Entity F has 2 children
Entity A has 2 children
Entity B has 1 children
Entity C has 1 children
Entity D has 2 children
Entity E has 0 children
Entity F has 0 children
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesA "normal" level of difficulty; suitable for simple features or challenging fixesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!X-ControversialThere is active debate or serious implications around merging this PRThere is active debate or serious implications around merging this PR