Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -3554,7 +3554,7 @@ protected internal override void InternalOnNetworkPostSpawn()
}

// Standard non-authority synchronization is handled here
if (!CanCommitToTransform && NetworkManager.IsConnectedClient && SynchronizeState.IsSynchronizing)
if (!CanCommitToTransform && m_CachedNetworkManager.IsConnectedClient && SynchronizeState.IsSynchronizing)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change useful on an optimization point of view?

{
NonAuthorityFinalizeSynchronization();
}
Expand Down Expand Up @@ -3625,9 +3625,9 @@ private void CleanUpOnDestroyOrDespawn()
#else
var forUpdate = true;
#endif
if (m_CachedNetworkObject != null)
if (m_CachedNetworkObject)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rider suggested converting "==" to explicit Unity engine object lifetime check. Should we keep or revert those changes?

{
NetworkManager?.NetworkTransformRegistration(m_CachedNetworkObject, forUpdate, false);
m_CachedNetworkManager?.NetworkTransformRegistration(m_CachedNetworkObject, forUpdate, false);
}

DeregisterForTickUpdate(this);
Expand Down Expand Up @@ -3673,7 +3673,7 @@ protected virtual void OnInitialize(ref NetworkVariable<NetworkTransformState> r
/// </summary>
private void ResetInterpolatedStateToCurrentAuthoritativeState()
{
var serverTime = NetworkManager.ServerTime.Time;
var serverTime = m_CachedNetworkManager.ServerTime.Time;
#if COM_UNITY_MODULES_PHYSICS || COM_UNITY_MODULES_PHYSICS2D
var position = m_UseRigidbodyForMotion ? m_NetworkRigidbodyInternal.GetPosition() : GetSpaceRelativePosition();
var rotation = m_UseRigidbodyForMotion ? m_NetworkRigidbodyInternal.GetRotation() : GetSpaceRelativeRotation();
Expand All @@ -3695,7 +3695,7 @@ private void ResetInterpolatedStateToCurrentAuthoritativeState()
}
private NetworkObject m_CachedNetworkObject;
/// <summary>
/// The internal initialzation method to allow for internal API adjustments
/// The internal initialization method to allow for internal API adjustments
/// </summary>
/// <param name="isOwnershipChange"></param>
private void InternalInitialization(bool isOwnershipChange = false)
Expand All @@ -3707,7 +3707,7 @@ private void InternalInitialization(bool isOwnershipChange = false)
m_CachedNetworkObject = NetworkObject;

// Determine if this is the first NetworkTransform in the associated NetworkObject's list
m_IsFirstNetworkTransform = NetworkObject.NetworkTransforms[0] == this;
m_IsFirstNetworkTransform = m_CachedNetworkObject.NetworkTransforms[0] == this;

if (m_CachedNetworkManager && m_CachedNetworkManager.DistributedAuthorityMode)
{
Expand All @@ -3719,7 +3719,7 @@ private void InternalInitialization(bool isOwnershipChange = false)
{
if (CanCommitToTransform)
{
if (NetworkObject.HasParentNetworkObject(transform))
if (m_CachedNetworkObject.HasParentNetworkObject(transform))
{
InLocalSpace = true;
}
Expand Down Expand Up @@ -3763,7 +3763,7 @@ private void InternalInitialization(bool isOwnershipChange = false)
if (CanCommitToTransform)
{
// Make sure authority doesn't get added to updates (no need to do this on the authority side)
m_CachedNetworkManager.NetworkTransformRegistration(NetworkObject, forUpdate, false);
m_CachedNetworkManager.NetworkTransformRegistration(m_CachedNetworkObject, forUpdate, false);
if (UseHalfFloatPrecision)
{
m_HalfPositionState = new NetworkDeltaPosition(currentPosition, m_CachedNetworkManager.ServerTime.Tick, math.bool3(SyncPositionX, SyncPositionY, SyncPositionZ));
Expand Down Expand Up @@ -3792,7 +3792,7 @@ private void InternalInitialization(bool isOwnershipChange = false)
m_PreviousScaleLerpSmoothing = ScaleLerpSmoothing;

// Non-authority needs to be added to updates for interpolation and applying state purposes
m_CachedNetworkManager.NetworkTransformRegistration(NetworkObject, forUpdate, true);
m_CachedNetworkManager.NetworkTransformRegistration(m_CachedNetworkObject, forUpdate, true);
// Remove this instance from the tick update
DeregisterForTickUpdate(this);
ResetInterpolatedStateToCurrentAuthoritativeState();
Expand Down Expand Up @@ -3890,7 +3890,7 @@ private void DefaultParentChanged()
m_RotationInterpolator.Clear();

// Always use NetworkManager here as this can be invoked prior to spawning
var tempTime = new NetworkTime(NetworkManager.NetworkConfig.TickRate, NetworkManager.ServerTime.Tick).Time;
var tempTime = new NetworkTime(NetworkManager.NetworkConfig.TickRate, m_CachedNetworkManager.ServerTime.Tick).Time;
UpdatePositionInterpolator(m_InternalCurrentPosition, tempTime, true);
m_ScaleInterpolator.ResetTo(m_InternalCurrentScale, tempTime);
m_RotationInterpolator.ResetTo(m_InternalCurrentRotation, tempTime);
Expand Down Expand Up @@ -3922,7 +3922,7 @@ internal override void InternalOnNetworkObjectParentChanged(NetworkObject parent
if (LastTickSync == m_LocalAuthoritativeNetworkState.GetNetworkTick())
{
m_InternalCurrentPosition = m_LastStateTargetPosition = GetSpaceRelativePosition();
m_PositionInterpolator.ResetTo(m_PositionInterpolator.Parent, m_InternalCurrentPosition, NetworkManager.ServerTime.Time);
m_PositionInterpolator.ResetTo(m_PositionInterpolator.Parent, m_InternalCurrentPosition, m_CachedNetworkManager.ServerTime.Time);
if (InLocalSpace)
{
transform.localPosition = m_InternalCurrentPosition;
Expand Down Expand Up @@ -3954,7 +3954,7 @@ internal override void InternalOnNetworkObjectParentChanged(NetworkObject parent
{
m_InternalCurrentRotation = GetSpaceRelativeRotation();
m_TargetRotation = m_InternalCurrentRotation.eulerAngles;
m_RotationInterpolator.ResetTo(m_RotationInterpolator.Parent, m_InternalCurrentRotation, NetworkManager.ServerTime.Time);
m_RotationInterpolator.ResetTo(m_RotationInterpolator.Parent, m_InternalCurrentRotation, m_CachedNetworkManager.ServerTime.Time);
if (InLocalSpace)
{
transform.localRotation = m_InternalCurrentRotation;
Expand Down Expand Up @@ -4638,13 +4638,13 @@ private void UpdateTransformState()
{
continue;
}
NetworkManager.MessageManager.SendMessage(ref m_OutboundMessage, networkDelivery, clientId);
m_CachedNetworkManager.MessageManager.SendMessage(ref m_OutboundMessage, networkDelivery, clientId);
}
}
else
{
// Clients (owner authoritative) send messages to the server-host
NetworkManager.MessageManager.SendMessage(ref m_OutboundMessage, networkDelivery, NetworkManager.ServerClientId);
m_CachedNetworkManager.MessageManager.SendMessage(ref m_OutboundMessage, networkDelivery, NetworkManager.ServerClientId);
}
m_LocalAuthoritativeNetworkState.LastSerializedSize = m_OutboundMessage.BytesWritten;
}
Expand Down Expand Up @@ -4783,7 +4783,7 @@ public NetworkTransformTickRegistration(NetworkManager networkManager)
internal void RegisterForTickSynchronization()
{
s_TickSynchPosition++;
m_NextTickSync = NetworkManager.ServerTime.Tick + (s_TickSynchPosition % (int)NetworkManager.NetworkConfig.TickRate);
m_NextTickSync = m_CachedNetworkManager.ServerTime.Tick + (s_TickSynchPosition % (int)NetworkManager.NetworkConfig.TickRate);
}

private static void RegisterNetworkManagerForTickUpdate(NetworkManager networkManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ public NetworkObject NetworkObject
{
get
{
if (m_NetworkObject != null)
if (m_NetworkObject)
{
return m_NetworkObject;
}
Expand All @@ -594,7 +594,7 @@ public NetworkObject NetworkObject
// or NetworkBehaviour.IsSpawned (i.e. to early exit if not spawned) which, in turn, could generate several Warning messages
// per spawned NetworkObject. Checking for ShutdownInProgress prevents these unnecessary LogWarning messages.
// We must check IsSpawned, otherwise a warning will be logged under certain valid conditions (see OnDestroy)
if (IsSpawned && m_NetworkObject == null && (m_NetworkManager == null || !m_NetworkManager.ShutdownInProgress))
if (IsSpawned && !m_NetworkObject && (!m_NetworkManager || !m_NetworkManager.ShutdownInProgress))
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Normal)
{
Expand Down
Loading