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

Avoid panic when getting EntityCommands in hierarchy #666

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion lightyear/src/shared/replication/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ impl<R: ReplicationSend> HierarchySendPlugin<R> {
continue;
}
trace!("Propagate Replicate through hierarchy: adding Replicate on child: {child:?}");
let Some(mut child_commands) = commands.get_entity(child) else {
continue;
};
// no need to set the correct parent as it will be set later in the `update_parent_sync` system
commands.entity(child).insert((
child_commands.insert((
// TODO: should we add replicating?
Replicating,
// the entire hierarchy is replicated as a single group so we re-use the parent's replication group id
Expand Down Expand Up @@ -514,4 +517,38 @@ mod tests {
&ParentSync(Some(server_parent))
);
}

#[test]
fn test_remove_child() {
let mut stepper = BevyStepper::default();
let child = stepper
.client_app
.world_mut()
.spawn(ComponentSyncModeFull(0.0))
.id();
let parent = stepper
.client_app
.world_mut()
.spawn((ComponentSyncModeSimple(0.0), client::Replicate::default()))
.add_child(child)
.id();
stepper
.client_app
.world_mut()
.commands()
.entity(child)
.despawn();

for _ in 0..10 {
stepper.frame_step();
}

// check that child was removed
let server_child = stepper
.server_app
.world_mut()
.query_filtered::<Entity, With<ComponentSyncModeFull>>()
.get_single(stepper.server_app.world());
assert_eq!(server_child.is_err(), true);
}
}
Loading