diff --git a/Assets/Mirror/Runtime/NetworkServer.cs b/Assets/Mirror/Runtime/NetworkServer.cs index 6a641d425..7d7c3a26e 100644 --- a/Assets/Mirror/Runtime/NetworkServer.cs +++ b/Assets/Mirror/Runtime/NetworkServer.cs @@ -1609,16 +1609,19 @@ static void Broadcast() connection.Update(); } - // TODO we already clear the serialized component's dirty bits above - // might as well clear everything??? - // - // TODO this unfortunately means we still need to iterate ALL - // spawned and not just the ones with observers. figure - // out a way to get rid of this. - // - // TODO clear dirty bits when removing the last observer instead! - // no need to do it for ALL entities ALL the time. + // TODO this is way too slow because we iterate ALL spawned :/ + // TODO this is way too complicated :/ + // to understand what this tries to prevent, consider this example: + // monster has health=100 + // we change health=200, dirty bit is set + // player comes in range, gets full serialization spawn packet. + // next Broadcast(), player gets the health=200 change because dirty bit was set. // + // this code clears all dirty bits if no players are around to prevent it. + // BUT there are two issues: + // 1. what if a playerB was around the whole time? + // 2. why don't we handle broadcast and spawn packets both HERE? + // handling spawn separately is why we need this complex magic ClearSpawnedDirtyBits(); }