Skip to content

Commit a8b7e9b

Browse files
test
Adding another integration test to validate this fix.
1 parent 08e2075 commit a8b7e9b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectDontDestroyWithOwnerTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ protected override bool UseCMBService()
2323
}
2424

2525
protected GameObject m_PrefabToSpawn;
26+
protected GameObject m_PrefabNoObserversSpawn;
2627

2728
public NetworkObjectDontDestroyWithOwnerTests(HostOrServer hostOrServer) : base(hostOrServer) { }
2829

2930
protected override void OnServerAndClientsCreated()
3031
{
3132
m_PrefabToSpawn = CreateNetworkObjectPrefab("ClientOwnedObject");
3233
m_PrefabToSpawn.GetComponent<NetworkObject>().DontDestroyWithOwner = true;
34+
35+
m_PrefabNoObserversSpawn = CreateNetworkObjectPrefab("NoObserversObject");
36+
var prefabNoObserversNetworkObject = m_PrefabNoObserversSpawn.GetComponent<NetworkObject>();
37+
prefabNoObserversNetworkObject.SpawnWithObservers = false;
38+
prefabNoObserversNetworkObject.DontDestroyWithOwner = true;
3339
}
3440

3541
[UnityTest]
@@ -74,5 +80,30 @@ public IEnumerator DontDestroyWithOwnerTest()
7480
Assert.That(networkObject.OwnerClientId == m_ServerNetworkManager.LocalClientId);
7581
}
7682
}
83+
84+
[UnityTest]
85+
public IEnumerator NetworkShowThenClientDisconnects()
86+
{
87+
var authorityManager = GetAuthorityNetworkManager();
88+
var networkObject = SpawnObject(m_PrefabNoObserversSpawn, authorityManager).GetComponent<NetworkObject>();
89+
var longWait = new WaitForSeconds(0.25f);
90+
yield return longWait;
91+
var nonAuthorityManager = GetNonAuthorityNetworkManager();
92+
Assert.False(nonAuthorityManager.SpawnManager.SpawnedObjects.ContainsKey(networkObject.NetworkObjectId), $"[Client-{nonAuthorityManager.LocalClientId}] " +
93+
$"Already has an instance of {networkObject.name} when it should not!");
94+
networkObject.NetworkShow(nonAuthorityManager.LocalClientId);
95+
networkObject.ChangeOwnership(nonAuthorityManager.LocalClientId);
96+
97+
yield return WaitForConditionOrTimeOut(() => nonAuthorityManager.SpawnManager.SpawnedObjects.ContainsKey(networkObject.NetworkObjectId)
98+
&& nonAuthorityManager.SpawnManager.SpawnedObjects[networkObject.NetworkObjectId].OwnerClientId == nonAuthorityManager.LocalClientId);
99+
AssertOnTimeout($"[Client-{nonAuthorityManager.LocalClientId}] Failed to spawn {networkObject.name} when it was shown!");
100+
101+
yield return s_DefaultWaitForTick;
102+
103+
nonAuthorityManager.Shutdown();
104+
105+
yield return longWait;
106+
Assert.True(networkObject.IsSpawned, $"The spawned test prefab was despawned on the authority side when it shouldn't have been!");
107+
}
77108
}
78109
}

0 commit comments

Comments
 (0)