Skip to content

Commit

Permalink
fix(NetworkWorld): fixing add identity when object is destroyed clien…
Browse files Browse the repository at this point in the history
…t side

if an object is destroyed locally client side it wont be removed from world, but if the server then respawns it then world will throw an error because netid already exists there. It should instead check if the existing object is null or not, If it is then it is ok to add a new one.
  • Loading branch information
James-Frowen committed Dec 29, 2021
1 parent 606423d commit b5a765e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Assets/Mirage/Runtime/NetworkWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ public bool TryGetIdentity(uint netId, out NetworkIdentity identity)
internal void AddIdentity(uint netId, NetworkIdentity identity)
{
if (netId == 0) throw new ArgumentException("id can not be zero", nameof(netId));
if (SpawnedObjects.ContainsKey(netId)) throw new ArgumentException("An item with same id already exists", nameof(netId));
if (identity == null) throw new ArgumentNullException(nameof(identity));
if (netId != identity.NetId) throw new ArgumentException("NetworkIdentity did not have matching netId", nameof(identity));
if (SpawnedObjects.TryGetValue(netId, out NetworkIdentity existing) && existing != null) throw new ArgumentException("An Identity with same id already exists in network world", nameof(netId));

SpawnedObjects.Add(netId, identity);
// dont use add, netid might already exist but have been destroyed
// this canhappen client side. we check for this case in TryGetValue above
SpawnedObjects[netId] = identity;
onSpawn?.Invoke(identity);
}

Expand Down

0 comments on commit b5a765e

Please sign in to comment.