Skip to content

Commit 6b2f648

Browse files
fix
Fixing issue where a `NetworkObject` with nested `NetworkTransform` components using different `NetworkTransform.AuthorityMode` settings stop updating non-authority instances, because the first authority instance removes the entire `NetworkObject` from the update registration.
1 parent 47bd434 commit 6b2f648

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

‎com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3715,6 +3715,28 @@ private void ResetInterpolatedStateToCurrentAuthoritativeState()
37153715
m_ScaleInterpolator.ResetTo(transform.parent, transform.localScale, serverTime);
37163716
}
37173717

3718+
/// <summary>
3719+
/// Determines whether any <see cref="NetworkTransform"/> on this <see cref="NetworkObject"/> is non-authority.
3720+
/// </summary>
3721+
/// <remarks>
3722+
/// Authority is derived the same way <see cref="InternalInitialization"/> derives it rather than read from
3723+
/// <see cref="CanCommitToTransform"/>, so the result does not depend upon the order in which the nested
3724+
/// <see cref="NetworkTransform"/> components are initialized.
3725+
/// </remarks>
3726+
private bool HasNonAuthorityNetworkTransform()
3727+
{
3728+
var networkTransforms = NetworkObject.NetworkTransforms;
3729+
for (int i = 0; i < networkTransforms.Count; i++)
3730+
{
3731+
var networkTransform = networkTransforms[i];
3732+
if (!(networkTransform.IsServerAuthoritative() ? networkTransform.IsServer : networkTransform.IsOwner))
3733+
{
3734+
return true;
3735+
}
3736+
}
3737+
return false;
3738+
}
3739+
37183740
/// <summary>
37193741
/// The internal initialization method to allow for internal API adjustments
37203742
/// </summary>
@@ -3777,8 +3799,13 @@ private void InternalInitialization(bool isOwnershipChange = false)
37773799

37783800
if (CanCommitToTransform)
37793801
{
3780-
// Make sure authority doesn't get added to updates (no need to do this on the authority side)
3781-
m_CachedNetworkManager.NetworkTransformRegistration(NetworkObject, forUpdate, false);
3802+
// Make sure authority doesn't get added to updates (no need to do this on the authority side), but the
3803+
// registration is per-NetworkObject while the authority motion model is per-NetworkTransform. Nested
3804+
// instances with the inverted authority mode still need the update.
3805+
if (!HasNonAuthorityNetworkTransform())
3806+
{
3807+
m_CachedNetworkManager.NetworkTransformRegistration(NetworkObject, forUpdate, false);
3808+
}
37823809
if (UseHalfFloatPrecision)
37833810
{
37843811
m_HalfPositionState = new NetworkDeltaPosition(currentPosition, m_CachedNetworkManager.ServerTime.Tick, math.bool3(SyncPositionX, SyncPositionY, SyncPositionZ));

0 commit comments

Comments
 (0)