The title is what I think is happening. We see this most noticeable with ghosts teleporting to an older position before teleporting back. The most reproducible trigger is when we add a debug component to a ghost on the server, wait about a second, and then remove it again.
NetDbg looks like this:
The purple line is the snapshot age, which goes up a lot when we remove the component.
My hypothesis here is that the ghost uses an old snapshot when it is moved back to an old chunk. I think I fixed this by clearing the snapshot history on all the entities not used in the chunk (see diff below), but I’m sure there is some nuance here that I am missing so any feedback would be welcome
diff --git a/Packages/netcode/Runtime/Snapshot/GhostSendSystem.cs b/Packages/netcode/Runtime/Snapshot/GhostSendSystem.cs
index 9e95b0ac8..5b6d5cfc5 100644
--- a/Packages/netcode/Runtime/Snapshot/GhostSendSystem.cs
+++ b/Packages/netcode/Runtime/Snapshot/GhostSendSystem.cs
@@ -1167,6 +1167,19 @@ namespace Unity.NetCode
}
}
+ // Clear data from entities which has moved from the chunk
+ if (chunkSerializationData.TryGetValue(chunk, out var chunkData))
+ {
+ for (ent = chunk.Count; ent < chunk.Capacity; ++ent)
+ {
+ for (int hp = 0; hp < GhostSystemConstants.SnapshotHistorySize; ++hp)
+ {
+ var clearSnapshotEntity = chunkData.GetEntity(snapshotSize, chunk.Capacity, hp);
+ clearSnapshotEntity[ent] = Entity.Null;
+ }
+ }
+ }
+
uint anyChangeMask = 0;
int skippedEntityCount = 0;
int relevantGhostCount = chunk.Count - serialChunks[pc].startIndex - irrelevantCount;