diff --git a/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs b/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs index c3c194bef..403165b98 100644 --- a/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs @@ -1329,6 +1329,43 @@ public void GetSyncVarNetworkIdentityOnServerNull() NetworkServer.Shutdown(); Transport.activeTransport = null; } + + [Test] + public void GetSyncVarNetworkIdentityOnClient() + { + // are we on client and not on server? + identity.isClient = true; + Assert.That(identity.isServer, Is.False); + + // add test component + NetworkBehaviourGetSyncVarNetworkIdentityComponent comp = gameObject.AddComponent(); + comp.syncInterval = 0; // for isDirty check + + // create a syncable GameObject + GameObject go = new GameObject(); + NetworkIdentity ni = go.AddComponent(); + ni.netId = 43; + + // register in spawned dict because clients should look it up via + // netId + NetworkIdentity.spawned[ni.netId] = ni; + + // assign ONLY netId in the component. assume that GameObject was + // assigned earlier but client walked so far out of range that it + // was despawned on the client. so it's forced to do the netId look- + // up. + Assert.That(comp.test, Is.Null); + comp.testNetId = ni.netId; + + // get it on the client. should look up netId in spawned + NetworkIdentity result = comp.GetSyncVarNetworkIdentityExposed(); + Assert.That(result, Is.EqualTo(ni)); + + // clean up + NetworkServer.Shutdown(); + Transport.activeTransport = null; + GameObject.DestroyImmediate(go); + } } // we need to inherit from networkbehaviour to test protected functions