@@ -368,6 +368,8 @@ private void UnifiedValidation()
368368 {
369369 NetworkObjectBridge = gameObject . AddComponent < NetworkObjectBridge > ( ) ;
370370 HadBridge = true ;
371+ // Transform synchronization is handled by unified netcode
372+ SynchronizeTransform = false ;
371373 }
372374 }
373375 }
@@ -2696,35 +2698,78 @@ internal List<NetworkBehaviour> ChildNetworkBehaviours
26962698 {
26972699 continue ;
26982700 }
2699-
2700- // Set ourselves as the NetworkObject that this behaviour belongs to and add it to the child list
2701- var nextIndex = ( ushort ) m_ChildNetworkBehaviours . Count ;
2702- networkBehaviours [ i ] . SetNetworkObject ( this , nextIndex ) ;
2703- m_ChildNetworkBehaviours . Add ( networkBehaviours [ i ] ) ;
2704-
27052701 var type = networkBehaviours [ i ] . GetType ( ) ;
2702+ #if COM_UNITY_MODULES_PHYSICS || COM_UNITY_MODULES_PHYSICS2D
2703+ if ( type . IsSubclassOf ( typeof ( NetworkRigidbodyBase ) ) )
2704+ {
2705+ var networkRigidbody = networkBehaviours [ i ] as NetworkRigidbodyBase ;
2706+
2707+ if ( NetworkRigidbodies == null )
2708+ {
2709+ NetworkRigidbodies = new List < NetworkRigidbodyBase > ( ) ;
2710+ }
2711+ NetworkRigidbodies . Add ( networkRigidbody ) ;
2712+ #if UNIFIED_NETCODE
2713+ // For now, we will just destroy these components during runtime since they will not
2714+ // be supported in hybrid mode (don't add to the children).
2715+ if ( HasGhost )
2716+ {
2717+ continue ;
2718+ }
2719+ #endif
2720+ }
2721+ else
2722+ #endif
27062723 if ( type == typeof ( NetworkTransform ) || type . IsInstanceOfType ( typeof ( NetworkTransform ) ) || type . IsSubclassOf ( typeof ( NetworkTransform ) ) )
27072724 {
2725+ var networkTransform = networkBehaviours [ i ] as NetworkTransform ;
2726+
27082727 if ( NetworkTransforms == null )
27092728 {
27102729 NetworkTransforms = new List < NetworkTransform > ( ) ;
27112730 }
2712- var networkTransform = networkBehaviours [ i ] as NetworkTransform ;
2731+
27132732 networkTransform . IsNested = i != 0 && networkTransform . gameObject != gameObject ;
27142733 NetworkTransforms . Add ( networkTransform ) ;
2715- }
2716- #if COM_UNITY_MODULES_PHYSICS || COM_UNITY_MODULES_PHYSICS2D
2717- else if ( type . IsSubclassOf ( typeof ( NetworkRigidbodyBase ) ) )
2718- {
2719- if ( NetworkRigidbodies == null )
2734+ #if UNIFIED_NETCODE
2735+ // For now, we will just destroy these components during runtime since they will not
2736+ // be supported in hybrid mode (don't add to the children).
2737+ if ( HasGhost )
27202738 {
2721- NetworkRigidbodies = new List < NetworkRigidbodyBase > ( ) ;
2739+ continue ;
27222740 }
2723- NetworkRigidbodies . Add ( networkBehaviours [ i ] as NetworkRigidbodyBase ) ;
2724- }
27252741#endif
2742+ }
2743+
2744+ // Set ourselves as the NetworkObject that this behaviour belongs to and add it to the child list
2745+ var nextIndex = ( ushort ) m_ChildNetworkBehaviours . Count ;
2746+ networkBehaviours [ i ] . SetNetworkObject ( this , nextIndex ) ;
2747+
2748+ // Finally, add the NetworkBehaviour to the list of child NetworkBehaviours
2749+ m_ChildNetworkBehaviours . Add ( networkBehaviours [ i ] ) ;
27262750 }
27272751
2752+ #if UNIFIED_NETCODE
2753+ // For now, cycle through all known NetworkTransform and NetworkRigidbodyBase derived components
2754+ // and destroy them all if this is a hybrid prefab instance.
2755+ // This allows a user to not have to make direct adjustments until trying out their NGO prefab
2756+ // as a hybrid spawned prefab (optional to completely remove, will eventually become obsolete and
2757+ // automatically removed later).
2758+ if ( HasGhost )
2759+ {
2760+ for ( int i = NetworkRigidbodies . Count - 1 ; i >= 0 ; i -- )
2761+ {
2762+ Destroy ( NetworkRigidbodies [ i ] ) ;
2763+ }
2764+ for ( int i = NetworkTransforms . Count - 1 ; i >= 0 ; i -- )
2765+ {
2766+ Destroy ( NetworkTransforms [ i ] ) ;
2767+ }
2768+ NetworkRigidbodies . Clear ( ) ;
2769+ NetworkTransforms . Clear ( ) ;
2770+ }
2771+ #endif
2772+
27282773 return m_ChildNetworkBehaviours ;
27292774 }
27302775 }
@@ -3572,7 +3617,7 @@ private void Start()
35723617 Debug . LogWarning ( $ "[{ nameof ( NetworkObject ) } ][{ name } ] Was not enabled on start! Enabling.") ;
35733618 enabled = true ;
35743619 }
3575-
3620+
35763621 InitGhost ( ) ;
35773622 }
35783623 [ SerializeField ]
0 commit comments