66using System . Runtime . CompilerServices ;
77using System . Text ;
88using NUnit . Framework ;
9+ #if UNIFIED_NETCODE
910using Unity . NetCode ;
11+ #endif
1012using Unity . Netcode . RuntimeTests ;
1113using Unity . Netcode . Transports . UTP ;
1214using UnityEngine ;
@@ -1758,6 +1760,7 @@ protected void DestroySceneNetworkObjects()
17581760
17591761 if ( CanDestroyNetworkObject ( networkObject ) )
17601762 {
1763+ #if UNIFIED_NETCODE
17611764 // Handle removing the prefab reference and destroying it
17621765 // and then destroying the ghostAdapter prior to destroying
17631766 // a hybrid prefab.
@@ -1770,7 +1773,7 @@ protected void DestroySceneNetworkObjects()
17701773 Object . Destroy ( prefabReference ) ;
17711774 Object . Destroy ( ghostAdapter ) ;
17721775 }
1773-
1776+ #endif
17741777 // Destroy the GameObject that holds the NetworkObject component
17751778 Object . DestroyImmediate ( networkObject . gameObject ) ;
17761779 }
@@ -2387,7 +2390,14 @@ protected void SpawnObjectInstance(NetworkObject networkObjectToSpawn, NetworkMa
23872390 private GameObject SpawnObject ( NetworkObject prefabNetworkObject , NetworkManager owner , bool destroyWithScene = false , bool isPlayerObject = false )
23882391 {
23892392 Assert . IsTrue ( prefabNetworkObject . GlobalObjectIdHash > 0 , $ "{ nameof ( GameObject ) } { prefabNetworkObject . name } has a { nameof ( NetworkObject . GlobalObjectIdHash ) } value of 0! Make sure to make it a valid prefab before trying to spawn!") ;
2390- NetCode . Netcode . Instance . m_ActiveWorld = owner . NetcodeWorld ;
2393+ #if UNIFIED_NETCODE
2394+ // TODO-FixMe: NetCode.Netcode.Instance is a singleton and might cause issues
2395+ // assigning this.
2396+ if ( prefabNetworkObject . HasGhost )
2397+ {
2398+ NetCode . Netcode . Instance . m_ActiveWorld = owner . NetcodeWorld ;
2399+ }
2400+ #endif
23912401 var newInstance = Object . Instantiate ( prefabNetworkObject . gameObject ) ;
23922402 var networkObjectToSpawn = newInstance . GetComponent < NetworkObject > ( ) ;
23932403 SpawnObjectInstance ( networkObjectToSpawn , owner , destroyWithScene , isPlayerObject ) ;
0 commit comments