diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/PlayerSpawnObjectVisibilityTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/PlayerSpawnObjectVisibilityTests.cs
index 4b1f603965..e3369e53ff 100644
--- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/PlayerSpawnObjectVisibilityTests.cs
+++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/PlayerSpawnObjectVisibilityTests.cs
@@ -13,7 +13,6 @@ namespace Unity.Netcode.RuntimeTests
internal class PlayerSpawnObjectVisibilityTests : NetcodeIntegrationTest
{
protected override int NumberOfClients => 0;
-
public enum PlayerSpawnStages
{
OnNetworkSpawn,
@@ -63,6 +62,25 @@ protected override void OnCreatePlayerPrefab()
base.OnCreatePlayerPrefab();
}
+ ///
+ /// Bypassing this on v1.x as the deferred show message could be processed on the next
+ /// frame from when the client registers having connected.
+ ///
+ protected override bool ShouldWaitForNewClientToConnect(NetworkManager networkManager)
+ {
+ return false;
+ }
+
+ ///
+ /// Validate that the player object is spawned on the client side.
+ ///
+ ///
+ private bool ClientSpawnedPlayer()
+ {
+ var playerObject = m_ClientNetworkManagers[0].LocalClient.PlayerObject;
+ return playerObject != null && playerObject.IsSpawned && playerObject.IsOwner;
+ }
+
///
/// Tests the scenario where under a client-server network topology if a player prefab
/// is spawned by the server with no observers but the player prefab itself has server
@@ -81,7 +99,17 @@ public IEnumerator NetworkShowOnSpawnTest([Values] PlayerSpawnStages spawnStage)
yield return CreateAndStartNewClient();
- yield return new WaitForSeconds(0.25f);
+ // Wait for the new client to connect
+ yield return WaitForClientsConnectedOrTimeOut();
+ AssertOnTimeout($"Timed out waiting for client to connect!");
+ OnNewClientStartedAndConnected(m_ClientNetworkManagers[0]);
+
+ // Wait for the new client to have spawned the player
+ yield return WaitForConditionOrTimeOut(ClientSpawnedPlayer);
+ AssertOnTimeout($"Timed out waiting for client to spawn its player object!");
+
+ // Provide some time to assure there are no additional attempts to spawn the same instance
+ yield return new WaitForSeconds(0.5f);
NetcodeLogAssert.LogWasNotReceived(LogType.Warning, new Regex("but it is already in the spawned list!"));
var client = m_ClientNetworkManagers[0];