@@ -13,7 +13,6 @@ namespace Unity.Netcode.RuntimeTests
1313 internal class PlayerSpawnObjectVisibilityTests : NetcodeIntegrationTest
1414 {
1515 protected override int NumberOfClients => 0 ;
16-
1716 public enum PlayerSpawnStages
1817 {
1918 OnNetworkSpawn ,
@@ -63,6 +62,25 @@ protected override void OnCreatePlayerPrefab()
6362 base . OnCreatePlayerPrefab ( ) ;
6463 }
6564
65+ /// <summary>
66+ /// Bypassing this on v1.x as the deferred show message could be processed on the next
67+ /// frame from when the client registers having connected.
68+ /// </summary>
69+ protected override bool ShouldWaitForNewClientToConnect ( NetworkManager networkManager )
70+ {
71+ return false ;
72+ }
73+
74+ /// <summary>
75+ /// Validate that the player object is spawned on the client side.
76+ /// </summary>
77+ /// <returns></returns>
78+ private bool ClientSpawnedPlayer ( )
79+ {
80+ var playerObject = m_ClientNetworkManagers [ 0 ] . LocalClient . PlayerObject ;
81+ return playerObject != null && playerObject . IsSpawned && playerObject . IsOwner ;
82+ }
83+
6684 /// <summary>
6785 /// Tests the scenario where under a client-server network topology if a player prefab
6886 /// 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)
8199
82100 yield return CreateAndStartNewClient ( ) ;
83101
84- yield return new WaitForSeconds ( 0.25f ) ;
102+ // Wait for the new client to connect
103+ yield return WaitForClientsConnectedOrTimeOut ( ) ;
104+ AssertOnTimeout ( $ "Timed out waiting for client to connect!") ;
105+ OnNewClientStartedAndConnected ( m_ClientNetworkManagers [ 0 ] ) ;
106+
107+ // Wait for the new client to have spawned the player
108+ yield return WaitForConditionOrTimeOut ( ClientSpawnedPlayer ) ;
109+ AssertOnTimeout ( $ "Timed out waiting for client to spawn its player object!") ;
110+
111+ // Provide some time to assure there are no additional attempts to spawn the same instance
112+ yield return new WaitForSeconds ( 0.5f ) ;
85113
86114 NetcodeLogAssert . LogWasNotReceived ( LogType . Warning , new Regex ( "but it is already in the spawned list!" ) ) ;
87115 var client = m_ClientNetworkManagers [ 0 ] ;
0 commit comments