diff --git a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs index 8e7cc89de..d0134c85d 100644 --- a/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs @@ -215,6 +215,16 @@ public override bool OnRebuildObservers(HashSet observers, bo } } + class RebuildEmptyObserversNetworkBehaviour : NetworkBehaviour + { + public override bool OnRebuildObservers(HashSet observers, bool initialize) + { + // return true so that caller knows we implemented + // OnRebuildObservers, but return no observers + return true; + } + } + class IsClientServerCheckComponent : NetworkBehaviour { // OnStartClient @@ -1305,5 +1315,28 @@ public void GetNewObserversFalseIfNoComponents() bool result = identity.GetNewObservers(observers, true); Assert.That(result, Is.False); } + + // RebuildObservers should always add the own ready connection + // (if any). fixes https://github.com/vis2k/Mirror/issues/692 + [Test] + public void RebuildObserversAddsOwnReadyPlayer() + { + // add at least one observers component, otherwise it will just add + // all server connections + gameObject.AddComponent(); + + // add own player connection + ULocalConnectionToClient connection = new ULocalConnectionToClient(); + connection.connectionToServer = new ULocalConnectionToServer(); + connection.isReady = true; + identity.connectionToClient = connection; + + // call OnStartServer so that observers dict is created + identity.OnStartServer(); + + // rebuild should at least add own ready player + identity.RebuildObservers(true); + Assert.That(identity.observers.ContainsKey(identity.connectionToClient.connectionId)); + } } }