diff --git a/client/src/lib.rs b/client/src/lib.rs
index 25411c1615..9e6646a1a5 100644
--- a/client/src/lib.rs
+++ b/client/src/lib.rs
@@ -2251,9 +2251,10 @@ impl Client {
self.dt_adjustment = dt_adjustment * time_scale.0;
},
ServerGeneral::EntitySync(entity_sync_package) => {
+ let uid = self.uid();
self.state
.ecs_mut()
- .apply_entity_sync_package(entity_sync_package);
+ .apply_entity_sync_package(entity_sync_package, uid);
},
ServerGeneral::CompSync(comp_sync_package, force_counter) => {
self.force_update_counter = force_counter;
@@ -2739,7 +2740,6 @@ impl Client {
let client_uid = self
.uid()
- .map(|u| u.into())
.expect("Client doesn't have a Uid!!!");
// Clear ecs of all entities
diff --git a/common/net/src/sync/sync_ext.rs b/common/net/src/sync/sync_ext.rs
index f46a2e239b..0875b1e1fe 100644
--- a/common/net/src/sync/sync_ext.rs
+++ b/common/net/src/sync/sync_ext.rs
@@ -25,7 +25,7 @@ pub trait WorldSyncExt {
&mut self,
entity_package: EntityPackage
,
) -> specs::Entity;
- fn apply_entity_sync_package(&mut self, package: EntitySyncPackage);
+ fn apply_entity_sync_package(&mut self, package: EntitySyncPackage, client_uid: Option);
fn apply_comp_sync_package(&mut self, package: CompSyncPackage);
}
@@ -103,7 +103,7 @@ impl WorldSyncExt for specs::World {
entity
}
- fn apply_entity_sync_package(&mut self, package: EntitySyncPackage) {
+ fn apply_entity_sync_package(&mut self, package: EntitySyncPackage, client_uid: Option) {
// Take ownership of the fields
let EntitySyncPackage {
created_entities,
@@ -117,7 +117,13 @@ impl WorldSyncExt for specs::World {
// Attempt to delete entities that were marked for deletion
deleted_entities.into_iter().for_each(|uid| {
- self.delete_entity_and_clear_from_id_maps(uid.into());
+ // Skip deleting the client's own entity. It will appear here when exiting
+ // "in-game" and the client already handles cleaning things up
+ // there. Although the client might not get this anyway since it
+ // should no longer be subscribed to any regions.
+ if client_uid != Some(uid) {
+ self.delete_entity_and_clear_from_id_maps(uid);
+ }
});
}
diff --git a/server/src/sys/entity_sync.rs b/server/src/sys/entity_sync.rs
index aa93568117..e10045f684 100644
--- a/server/src/sys/entity_sync.rs
+++ b/server/src/sys/entity_sync.rs
@@ -311,6 +311,8 @@ impl<'a> System<'a> for Sys {
}
}
+ // TODO: force update counter only needs to be sent with updates specifically
+ // for a client's own entity. We can save bandwidth here.
client.send_fallible(ServerGeneral::CompSync(
comp_sync_package,
force_updates.get(*client_entity).map_or(0, |f| f.counter()),
diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs
index 1ac783a20d..2f699d8810 100644
--- a/server/src/sys/sentinel.rs
+++ b/server/src/sys/sentinel.rs
@@ -1,4 +1,3 @@
-#![allow(clippy::large_enum_variant)]
use common::{
comp::{
item::{tool::AbilityMap, MaterialStatManifest},
@@ -277,7 +276,11 @@ use common_net::synced_components::*;
// of components. This will declare the types defined in the macro above.
common_net::synced_components!(trackers);
-/// Deleted entities grouped by region
+/// Deleted entities grouped by region.
+///
+/// Note, this is primarily for syncing purposes and can include the Uid of
+/// clients that have left "in-game" to return to the character screen (even
+/// though there is still an entity with this Uid!).
pub struct DeletedEntities {
map: HashMap, Vec>,
}