22using System . Collections . Generic ;
33using System . Linq ;
44using System . Runtime . CompilerServices ;
5+ using System . Text ;
56using Unity . Mathematics ;
67using Unity . Netcode . Transports . UTP ;
78using UnityEngine ;
@@ -2071,12 +2072,19 @@ private void OnNetworkTick()
20712072 // As long as we are still authority
20722073 if ( CanCommitToTransform )
20732074 {
2075+ if ( m_CachedNetworkManager . DistributedAuthorityMode && ! IsOwner )
2076+ {
2077+ Debug . LogError ( $ "Non-owner Client-{ m_CachedNetworkManager . LocalClientId } is being updated by network tick still!!!!") ;
2078+ }
20742079 // Update any changes to the transform
20752080 var transformSource = transform ;
20762081 OnUpdateAuthoritativeState ( ref transformSource ) ;
2077-
2082+ #if COM_UNITY_MODULES_PHYSICS
2083+ m_CurrentPosition = m_TargetPosition = m_UseRigidbodyForMotion ? m_NetworkRigidbodyInternal . GetPosition ( ) : GetSpaceRelativePosition ( ) ;
2084+ #else
20782085 m_CurrentPosition = GetSpaceRelativePosition ( ) ;
20792086 m_TargetPosition = GetSpaceRelativePosition ( ) ;
2087+ #endif
20802088 }
20812089 else // If we are no longer authority, unsubscribe to the tick event
20822090 if ( NetworkManager != null && NetworkManager . NetworkTickSystem != null )
@@ -2104,6 +2112,8 @@ internal void UpdatePositionInterpolator(Vector3 position, double time, bool res
21042112 }
21052113 }
21062114
2115+ internal bool LogMotion ;
2116+
21072117 /// <summary>
21082118 /// Applies the authoritative state to the transform
21092119 /// </summary>
@@ -2245,6 +2255,11 @@ private void ApplyAuthoritativeState()
22452255 if ( m_UseRigidbodyForMotion )
22462256 {
22472257 m_NetworkRigidbodyInternal . MovePosition ( m_CurrentPosition ) ;
2258+ if ( LogMotion )
2259+ {
2260+ Debug . Log ( $ "[Client-{ m_CachedNetworkManager . LocalClientId } ][Interpolate: { networkState . UseInterpolation } ][TransPos: { transform . position } ][RBPos: { m_NetworkRigidbodyInternal . GetPosition ( ) } ][CurrentPos: { m_CurrentPosition } ") ;
2261+ }
2262+
22482263 }
22492264 else
22502265#endif
@@ -2676,7 +2691,7 @@ protected virtual void OnNetworkTransformStateUpdated(ref NetworkTransformState
26762691
26772692 }
26782693
2679-
2694+ internal bool LogStateUpdate ;
26802695 /// <summary>
26812696 /// Only non-authoritative instances should invoke this method
26822697 /// </summary>
@@ -2698,6 +2713,24 @@ private void OnNetworkStateChanged(NetworkTransformState oldState, NetworkTransf
26982713 // Get the time when this new state was sent
26992714 newState . SentTime = new NetworkTime ( m_CachedNetworkManager . NetworkConfig . TickRate , newState . NetworkTick ) . Time ;
27002715
2716+ if ( LogStateUpdate )
2717+ {
2718+ var builder = new StringBuilder ( ) ;
2719+ builder . AppendLine ( $ "[Client-{ m_CachedNetworkManager . LocalClientId } ][State Update: { newState . GetNetworkTick ( ) } ][HasPos: { newState . HasPositionChange } ][Has Rot: { newState . HasRotAngleChange } ][Has Scale: { newState . HasScaleChange } ]") ;
2720+ if ( newState . HasPositionChange )
2721+ {
2722+ builder . AppendLine ( $ "Position = { newState . GetPosition ( ) } ") ;
2723+ }
2724+ if ( newState . HasRotAngleChange )
2725+ {
2726+ builder . AppendLine ( $ "Rotation = { newState . GetRotation ( ) } ") ;
2727+ }
2728+ if ( newState . HasScaleChange )
2729+ {
2730+ builder . AppendLine ( $ "Scale = { newState . GetScale ( ) } ") ;
2731+ }
2732+ Debug . Log ( builder ) ;
2733+ }
27012734 // Apply the new state
27022735 ApplyUpdatedState ( newState ) ;
27032736
@@ -3324,8 +3357,12 @@ public bool IsServerAuthoritative()
33243357 /// Invoked by <see cref="NetworkTransformMessage"/> to update the transform state
33253358 /// </summary>
33263359 /// <param name="networkTransformState"></param>
3327- internal void TransformStateUpdate ( ref NetworkTransformState networkTransformState )
3360+ internal void TransformStateUpdate ( ref NetworkTransformState networkTransformState , ulong senderId )
33283361 {
3362+ if ( CanCommitToTransform )
3363+ {
3364+ Debug . LogError ( $ "Authority receiving transform update from Client-{ senderId } !") ;
3365+ }
33293366 // Store the previous/old state
33303367 m_OldState = m_LocalAuthoritativeNetworkState ;
33313368
@@ -3364,7 +3401,7 @@ private void UpdateTransformState()
33643401 State = m_LocalAuthoritativeNetworkState ,
33653402 DistributedAuthorityMode = m_CachedNetworkManager . DistributedAuthorityMode ,
33663403 // Don't populate if we are the DAHost as we send directly to each client
3367- TargetIds = m_CachedNetworkManager . DistributedAuthorityMode && ! m_CachedNetworkManager . DAHost ? NetworkObject . Observers . ToArray ( ) : null ,
3404+ TargetIds = m_CachedNetworkManager . DistributedAuthorityMode && ! m_CachedNetworkManager . DAHost ? NetworkObject . Observers . Where ( ( c ) => c != m_CachedNetworkManager . LocalClientId ) . ToArray ( ) : null ,
33683405 } ;
33693406
33703407
0 commit comments