@@ -213,6 +213,11 @@ internal class TransitionStateinfo
213213 // [Layer][DestinationState][TransitionStateInfo]
214214 private Dictionary < int , Dictionary < int , TransitionStateinfo > > m_DestinationStateToTransitioninfo = new Dictionary < int , Dictionary < int , TransitionStateinfo > > ( ) ;
215215
216+ // Named differently to avoid serialization conflicts with NetworkBehaviour
217+ private NetworkManager m_LocalNetworkManager ;
218+
219+ internal bool DistributedAuthorityMode ;
220+
216221 /// <summary>
217222 /// Builds the m_DestinationStateToTransitioninfo lookup table
218223 /// </summary>
@@ -509,7 +514,12 @@ internal bool IsServerAuthoritative()
509514 /// </remarks>
510515 protected virtual bool OnIsServerAuthoritative ( )
511516 {
512- return NetworkManager ? ! NetworkManager . DistributedAuthorityMode : true ;
517+ if ( ! m_LocalNetworkManager )
518+ {
519+ return true ;
520+ }
521+
522+ return ! DistributedAuthorityMode ;
513523 }
514524
515525 private int [ ] m_TransitionHash ;
@@ -713,6 +723,10 @@ internal AnimationMessage GetAnimationMessage()
713723 /// <inheritdoc/>
714724 public override void OnNetworkSpawn ( )
715725 {
726+ // Save internal state references
727+ m_LocalNetworkManager = NetworkManager ;
728+ DistributedAuthorityMode = m_LocalNetworkManager . DistributedAuthorityMode ;
729+
716730 // If there is no assigned Animator then generate a server network warning (logged locally and if applicable on the server-host side as well).
717731 if ( m_Animator == null )
718732 {
@@ -963,7 +977,7 @@ internal void CheckForAnimatorChanges()
963977
964978 if ( m_Animator . runtimeAnimatorController == null )
965979 {
966- if ( NetworkManager . LogLevel == LogLevel . Developer )
980+ if ( m_LocalNetworkManager . LogLevel == LogLevel . Developer )
967981 {
968982 Debug . LogError ( $ "[{ GetType ( ) . Name } ] Could not find an assigned { nameof ( RuntimeAnimatorController ) } ! Cannot check { nameof ( Animator ) } for changes in state!") ;
969983 }
@@ -998,9 +1012,9 @@ internal void CheckForAnimatorChanges()
9981012 {
9991013 // Just notify all remote clients and not the local server
10001014 m_ClientSendList . Clear ( ) ;
1001- foreach ( var clientId in NetworkManager . ConnectionManager . ConnectedClientIds )
1015+ foreach ( var clientId in m_LocalNetworkManager . ConnectionManager . ConnectedClientIds )
10021016 {
1003- if ( clientId == NetworkManager . LocalClientId || ! NetworkObject . Observers . Contains ( clientId ) )
1017+ if ( clientId == m_LocalNetworkManager . LocalClientId || ! NetworkObject . Observers . Contains ( clientId ) )
10041018 {
10051019 continue ;
10061020 }
@@ -1028,7 +1042,7 @@ private void SendParametersUpdate(ClientRpcParams clientRpcParams = default, boo
10281042 }
10291043 else
10301044 {
1031- Debug . LogError ( $ "[{ name } ][Client-{ NetworkManager . LocalClientId } ] Attempting to send parameter updates but not the owner!") ;
1045+ Debug . LogError ( $ "[{ name } ][Client-{ m_LocalNetworkManager . LocalClientId } ] Attempting to send parameter updates but not the owner!") ;
10321046 }
10331047 }
10341048 else
@@ -1266,12 +1280,12 @@ internal void UpdateAnimationState(AnimationState animationState)
12661280 // Cross fade from the current to the destination state for the transitions duration while starting at the server's current normalized time of the transition
12671281 m_Animator . CrossFade ( transitionStateInfo . DestinationState , transitionStateInfo . TransitionDuration , transitionStateInfo . Layer , 0.0f , animationState . NormalizedTime ) ;
12681282 }
1269- else if ( NetworkManager . LogLevel == LogLevel . Developer )
1283+ else if ( m_LocalNetworkManager . LogLevel == LogLevel . Developer )
12701284 {
12711285 NetworkLog . LogWarning ( $ "Current State Hash ({ currentState . fullPathHash } ) != AnimationState.StateHash ({ animationState . StateHash } )") ;
12721286 }
12731287 }
1274- else if ( NetworkManager . LogLevel == LogLevel . Developer )
1288+ else if ( m_LocalNetworkManager . LogLevel == LogLevel . Developer )
12751289 {
12761290 NetworkLog . LogError ( $ "[DestinationState To Transition Info] Layer ({ animationState . Layer } ) sub-table does not contain destination state ({ animationState . DestinationStateHash } )!") ;
12771291 }
@@ -1314,7 +1328,8 @@ private unsafe void SendParametersUpdateServerRpc(ParametersUpdateMessage parame
13141328 return ;
13151329 }
13161330 UpdateParameters ( ref parametersUpdate ) ;
1317- if ( NetworkManager . ConnectedClientsIds . Count > ( IsHost ? 2 : 1 ) )
1331+ var connectedClientIds = m_LocalNetworkManager . ConnectionManager . ConnectedClientIds ;
1332+ if ( connectedClientIds . Count <= ( IsHost ? 2 : 1 ) )
13181333 {
13191334 m_ClientSendList . Clear ( ) ;
13201335 foreach ( var clientId in NetworkManager . ConnectionManager . ConnectedClientIds )
@@ -1377,7 +1392,8 @@ private void SendAnimStateServerRpc(AnimationMessage animationMessage, ServerRpc
13771392 UpdateAnimationState ( animationState ) ;
13781393 }
13791394
1380- if ( NetworkManager . ConnectedClientsIds . Count > ( IsHost ? 2 : 1 ) )
1395+ var connectedClientIds = m_LocalNetworkManager . ConnectionManager . ConnectedClientIds ;
1396+ if ( connectedClientIds . Count <= ( IsHost ? 2 : 1 ) )
13811397 {
13821398 m_ClientSendList . Clear ( ) ;
13831399 foreach ( var clientId in NetworkManager . ConnectionManager . ConnectedClientIds )
@@ -1416,7 +1432,7 @@ private void ProcessAnimStates(AnimationMessage animationMessage)
14161432 {
14171433 if ( HasAuthority )
14181434 {
1419- if ( NetworkManager . LogLevel == LogLevel . Developer )
1435+ if ( m_LocalNetworkManager . LogLevel == LogLevel . Developer )
14201436 {
14211437 var hostOrOwner = NetworkManager . DistributedAuthorityMode ? "Owner" : "Host" ;
14221438 var clientServerOrDAMode = NetworkManager . DistributedAuthorityMode ? "distributed authority" : "client-server" ;
@@ -1443,7 +1459,7 @@ internal void SendAnimTriggerServerRpc(AnimationTriggerMessage animationTriggerM
14431459 // Ignore if a non-owner sent this.
14441460 if ( serverRpcParams . Receive . SenderClientId != OwnerClientId )
14451461 {
1446- if ( NetworkManager . LogLevel == LogLevel . Developer )
1462+ if ( m_LocalNetworkManager . LogLevel == LogLevel . Developer )
14471463 {
14481464 NetworkLog . LogWarning ( $ "[Owner Authoritative] Detected the a non-authoritative client is sending the server animation trigger updates. If you recently changed ownership of the { name } object, then this could be the reason.") ;
14491465 }
@@ -1453,6 +1469,8 @@ internal void SendAnimTriggerServerRpc(AnimationTriggerMessage animationTriggerM
14531469 // set the trigger locally on the server
14541470 InternalSetTrigger ( animationTriggerMessage . Hash , animationTriggerMessage . IsTriggerSet ) ;
14551471
1472+ var connectedClientIds = m_LocalNetworkManager . ConnectionManager . ConnectedClientIds ;
1473+
14561474 m_ClientSendList . Clear ( ) ;
14571475 foreach ( var clientId in NetworkManager . ConnectionManager . ConnectedClientIds )
14581476 {
0 commit comments