@@ -2060,6 +2060,13 @@ internal void InvokeOwnershipChanged(ulong previous, ulong next)
20602060
20612061 internal void InvokeBehaviourOnNetworkObjectParentChanged ( NetworkObject parentNetworkObject )
20622062 {
2063+ if ( NetworkManagerOwner == null )
2064+ {
2065+ #if TEST_NO_SINGLETON
2066+ Debug . LogError ( "NetworkManagerOwner should be set! Setting owner to NetworkManager.Singleton" ) ;
2067+ #endif
2068+ NetworkManagerOwner = NetworkManager . Singleton ;
2069+ }
20632070 for ( int i = 0 ; i < ChildNetworkBehaviours . Count ; i ++ )
20642071 {
20652072 // Invoke internal notification
@@ -2288,6 +2295,13 @@ private void OnTransformParentChanged()
22882295
22892296 if ( ! IsSpawned )
22902297 {
2298+ if ( NetworkManagerOwner == null )
2299+ {
2300+ #if TEST_NO_SINGLETON
2301+ Debug . LogError ( "NetworkManagerOwner should be set! Setting owner to NetworkManager.Singleton" ) ;
2302+ #endif
2303+ NetworkManagerOwner = NetworkManager ;
2304+ }
22912305 AuthorityAppliedParenting = false ;
22922306 // and we are removing the parent, then go ahead and allow parenting to occur
22932307 if ( transform . parent == null )
@@ -2632,7 +2646,9 @@ private List<NetworkBehaviour> BuildChildBehavioursList()
26322646 {
26332647 if ( NetworkManagerOwner == null )
26342648 {
2649+ #if TEST_NO_SINGLETON
26352650 Debug . LogError ( "NetworkManagerOwner should be set! Setting owner to NetworkManager.Singleton" ) ;
2651+ #endif
26362652 NetworkManagerOwner = NetworkManager . Singleton ;
26372653 }
26382654
@@ -2759,6 +2775,15 @@ internal static void VerifyParentingStatus()
27592775 /// </returns>
27602776 public ushort GetNetworkBehaviourOrderIndex ( NetworkBehaviour instance )
27612777 {
2778+ if ( ! IsSpawned )
2779+ {
2780+ if ( NetworkLog . CurrentLogLevel <= LogLevel . Developer )
2781+ {
2782+ Debug . LogWarning ( $ "{ nameof ( NetworkObject ) } is not spawned yet. Cannot get index of NetworkBehaviour.") ;
2783+ }
2784+ return 0 ;
2785+ }
2786+
27622787 // read the cached index, and verify it first
27632788 if ( instance . NetworkBehaviourId < ChildNetworkBehaviours . Count )
27642789 {
@@ -2780,6 +2805,15 @@ public ushort GetNetworkBehaviourOrderIndex(NetworkBehaviour instance)
27802805 /// <returns>The <see cref="NetworkBehaviour"/> at the ordered index value or null if it does not exist.</returns>
27812806 public NetworkBehaviour GetNetworkBehaviourAtOrderIndex ( ushort index )
27822807 {
2808+ if ( ! IsSpawned )
2809+ {
2810+ if ( NetworkLog . CurrentLogLevel <= LogLevel . Developer )
2811+ {
2812+ Debug . LogWarning ( $ "{ nameof ( NetworkObject ) } is not spawned yet. Cannot get NetworkBehaviour at index.") ;
2813+ }
2814+ return null ;
2815+ }
2816+
27832817 if ( index >= ChildNetworkBehaviours . Count )
27842818 {
27852819 if ( NetworkLog . CurrentLogLevel <= LogLevel . Error )
0 commit comments