Skip to content

Commit 932cf44

Browse files
committed
Fix missing Remote marker on entities spawned by other components
Closes #672.
1 parent fb5851e commit 932cf44

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- `Replicated` is no longer automatically inserted on clients, only `Remote`. `scene::replicate_into` will serialize all entities that have either `Remote` or `Replicated`.
1313

14+
### Fixed
15+
16+
- Entities spawned during component deserialization now also get the `Remote` marker.
17+
1418
## [0.39.1] - 2026-03-09
1519

1620
### Fixed

src/client.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,13 @@ fn apply_changes(
537537
return Ok(());
538538
};
539539

540-
DeferredEntity::new(client_entity, params.changes)
540+
let mut client_entity = DeferredEntity::new(client_entity, params.changes);
541+
if !client_entity.contains::<Remote>() {
542+
// Even though the entity already exists, it could have been spawned during
543+
// deserialization of another component and doesn't have the marker yet.
544+
client_entity.insert(Remote);
545+
}
546+
client_entity
541547
}
542548
EntityEntry::Vacant(entry) => {
543549
let mut client_entity = DeferredEntity::new(world.spawn_empty(), params.changes);

tests/spawn.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,40 @@ fn old_component() {
149149
assert_eq!(components.iter(client_app.world()).count(), 1);
150150
}
151151

152+
#[test]
153+
fn related() {
154+
let mut server_app = App::new();
155+
let mut client_app = App::new();
156+
157+
for app in [&mut server_app, &mut client_app] {
158+
app.add_plugins((
159+
MinimalPlugins,
160+
StatesPlugin,
161+
RepliconPlugins.set(ServerPlugin::new(PostUpdate)),
162+
))
163+
.replicate::<ChildOf>()
164+
.finish();
165+
}
166+
167+
server_app.connect_client(&mut client_app);
168+
169+
let server_parent = server_app.world_mut().spawn(Replicated).id();
170+
server_app
171+
.world_mut()
172+
.spawn((Replicated, ChildOf(server_parent)));
173+
174+
server_app.update();
175+
server_app.exchange_with_client(&mut client_app);
176+
client_app.update();
177+
server_app.exchange_with_client(&mut client_app);
178+
179+
let mut children = client_app.world_mut().query::<&ChildOf>();
180+
assert_eq!(children.iter(client_app.world()).len(), 1);
181+
182+
let mut remote = client_app.world_mut().query::<&Remote>();
183+
assert_eq!(remote.iter(client_app.world()).len(), 2);
184+
}
185+
152186
#[test]
153187
fn empty_before_connection() {
154188
let mut server_app = App::new();

0 commit comments

Comments
 (0)