Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Fixed

- Fixed AnticipatedNetworkTransform not respecting the InLocalSpace flag (#3995)
- Issue where scene migration in a distributed authority session would throw an exception on clients migrating their owned `NetworkObject` instances to a different scene.(#4086)
- Issue where migrating a dynamically spawned or in-scene placed `NetworkObject` into a different scene during awake could result in that spawned instance to not be synchronized. (#4086)
- Issue where a NullReferenceException was thrown when a non-authority failed to spawn a NetworkObject. (#4067)
- Issue where the active scene was not being serialized as the 1st scene which could result in various errors including a soft synchronization error if, on the client-side, other synchronized scenes had already been loaded prior to the active scene, which is always loaded as `LoadSceneMode.SingleMode` when client synchronization is set to `LoadSceneMode.SingleMode`, resulting in the previously loaded scene(s) to be unloaded. (#4065)
- Issue when FastBufferReader is attempting to read a string and all or a portion of the character count has already been read by user script, it could read a character length that results in a negative byte length which could result in an editor crash. (#4052)
- Issue where NetworkRigidbodyBase was not applying rotation correctly when using Rigidbody2D. (#4012)
- Issue where NetworkRigidbodyBase was always checking the 3D rigid body's interpolation mode when determining if it is kinematic and needs to put the rigid body to sleep and then switch to interpolation. (#4012)
- Fixed AnticipatedNetworkTransform not respecting the InLocalSpace flag. (#3995)

### Security

Expand Down
10 changes: 5 additions & 5 deletions com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ public bool NotifyUserOfNestedNetworkManager(NetworkManager networkManager, bool
{
return isParented;
}
else // If we are no longer a child, then we can remove ourself from this list
if (transform.root == gameObject.transform)
{
s_LastKnownNetworkManagerParents.Remove(networkManager);
}
else if (transform.root == gameObject.transform)
{
// If we are no longer a child, then we can remove ourself from this list
s_LastKnownNetworkManagerParents.Remove(networkManager);
}
}
if (!EditorApplication.isUpdating && isParented)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,20 +467,20 @@ internal T Update(float deltaTime, double tickLatencyAsTime, double minDeltaTime
InterpolateState.CurrentValue = InterpolateState.NextValue;
}
}
else // If the target is reached and we have no more state updates, we want to check to see if we need to reset.
if (m_BufferQueue.Count == 0)
// If the target is reached and we have no more state updates, we want to check to see if we need to reset.
else if (m_BufferQueue.Count == 0)
{
// When the delta between the time sent and the current tick latency time-window is greater than the max delta time
// plus the minimum delta time (a rough estimate of time to wait before we consider rate of change equal to zero),
// we will want to reset the interpolator with the current known value. This prevents the next received state update's
// time to be calculated against the last calculated time which if there is an extended period of time between the two
// it would cause a large delta time period between the two states (i.e. it stops moving for a second or two and then
// starts moving again).
if ((tickLatencyAsTime - InterpolateState.Target.Value.TimeSent) > InterpolateState.MaxDeltaTime + minDeltaTime)
{
// When the delta between the time sent and the current tick latency time-window is greater than the max delta time
// plus the minimum delta time (a rough estimate of time to wait before we consider rate of change equal to zero),
// we will want to reset the interpolator with the current known value. This prevents the next received state update's
// time to be calculated against the last calculated time which if there is an extended period of time between the two
// it would cause a large delta time period between the two states (i.e. it stops moving for a second or two and then
// starts moving again).
if ((tickLatencyAsTime - InterpolateState.Target.Value.TimeSent) > InterpolateState.MaxDeltaTime + minDeltaTime)
{
InterpolateState.Reset(InterpolateState.CurrentValue);
}
InterpolateState.Reset(InterpolateState.CurrentValue);
}
}
}
m_NbItemsReceivedThisFrame = 0;
return InterpolateState.CurrentValue;
Expand Down Expand Up @@ -593,20 +593,20 @@ public T Update(float deltaTime, double renderTime, double serverTime)
// Determine if we have reached our target
InterpolateState.TargetReached = IsApproximately(InterpolateState.CurrentValue, InterpolateState.Target.Value.Item, GetPrecision());
}
else // If the target is reached and we have no more state updates, we want to check to see if we need to reset.
if (InterpolateState.TargetReached && m_BufferQueue.Count == 0)
// If the target is reached and we have no more state updates, we want to check to see if we need to reset.
else if (InterpolateState.TargetReached && m_BufferQueue.Count == 0)
{
// When the delta between the time sent and the current tick latency time-window is greater than the max delta time
// plus the minimum delta time (a rough estimate of time to wait before we consider rate of change equal to zero),
// we will want to reset the interpolator with the current known value. This prevents the next received state update's
// time to be calculated against the last calculated time which if there is an extended period of time between the two
// it would cause a large delta time period between the two states (i.e. it stops moving for a second or two and then
// starts moving again).
if ((renderTime - InterpolateState.Target.Value.TimeSent) > 0.3f) // If we haven't recevied anything within 300ms, assume we stopped motion.
{
// When the delta between the time sent and the current tick latency time-window is greater than the max delta time
// plus the minimum delta time (a rough estimate of time to wait before we consider rate of change equal to zero),
// we will want to reset the interpolator with the current known value. This prevents the next received state update's
// time to be calculated against the last calculated time which if there is an extended period of time between the two
// it would cause a large delta time period between the two states (i.e. it stops moving for a second or two and then
// starts moving again).
if ((renderTime - InterpolateState.Target.Value.TimeSent) > 0.3f) // If we haven't recevied anything within 300ms, assume we stopped motion.
{
InterpolateState.Reset(InterpolateState.CurrentValue);
}
InterpolateState.Reset(InterpolateState.CurrentValue);
}
}
m_NbItemsReceivedThisFrame = 0;
return InterpolateState.CurrentValue;
}
Expand Down
58 changes: 28 additions & 30 deletions com.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,26 +1180,25 @@ internal void CheckForAnimatorChanges()
{
SendAnimStateRpc(m_AnimationMessage);
}
else if (!IsServer && IsOwner)
{
SendServerAnimStateRpc(m_AnimationMessage);
}
else
if (!IsServer && IsOwner)
{
SendServerAnimStateRpc(m_AnimationMessage);
}
else
{
// Just notify all remote clients and not the local server
m_TargetGroup.Clear();
foreach (var clientId in LocalNetworkManager.ConnectionManager.ConnectedClientIds)
{
// Just notify all remote clients and not the local server
m_TargetGroup.Clear();
foreach (var clientId in LocalNetworkManager.ConnectionManager.ConnectedClientIds)
if (clientId == LocalNetworkManager.LocalClientId || !NetworkObject.Observers.Contains(clientId))
{
if (clientId == LocalNetworkManager.LocalClientId || !NetworkObject.Observers.Contains(clientId))
{
continue;
}
m_TargetGroup.Add(clientId);
continue;
}
m_RpcParams.Send.Target = m_TargetGroup.Target;
SendClientAnimStateRpc(m_AnimationMessage, m_RpcParams);
m_TargetGroup.Add(clientId);
}
m_RpcParams.Send.Target = m_TargetGroup.Target;
SendClientAnimStateRpc(m_AnimationMessage, m_RpcParams);
}
}
}

Expand Down Expand Up @@ -1346,25 +1345,24 @@ private unsafe void WriteParameters(ref FastBufferWriter writer)
BytePacker.WriteValuePacked(writer, (uint)valueInt);
}
}
else
if (cacheValue.Type == AnimationParamEnumWrapper.AnimatorControllerParameterBool)
else if (cacheValue.Type == AnimationParamEnumWrapper.AnimatorControllerParameterBool)
{
var valueBool = m_Animator.GetBool(hash);
fixed (void* value = cacheValue.Value)
{
var valueBool = m_Animator.GetBool(hash);
fixed (void* value = cacheValue.Value)
{
UnsafeUtility.WriteArrayElement(value, 0, valueBool);
BytePacker.WriteValuePacked(writer, valueBool);
}
UnsafeUtility.WriteArrayElement(value, 0, valueBool);
BytePacker.WriteValuePacked(writer, valueBool);
}
else if (cacheValue.Type == AnimationParamEnumWrapper.AnimatorControllerParameterFloat)
}
else if (cacheValue.Type == AnimationParamEnumWrapper.AnimatorControllerParameterFloat)
{
var valueFloat = m_Animator.GetFloat(hash);
fixed (void* value = cacheValue.Value)
{
var valueFloat = m_Animator.GetFloat(hash);
fixed (void* value = cacheValue.Value)
{
UnsafeUtility.WriteArrayElement(value, 0, valueFloat);
BytePacker.WriteValuePacked(writer, valueFloat);
}
UnsafeUtility.WriteArrayElement(value, 0, valueFloat);
BytePacker.WriteValuePacked(writer, valueFloat);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2515,24 +2515,24 @@ private bool CheckForStateChange(ref NetworkTransformState networkState, bool is
}
}
}
else // Just apply the full local scale when synchronizing
if (SynchronizeScale)
// Just apply the full local scale when synchronizing
else if (SynchronizeScale)
{
var localScale = CachedTransform.localScale;
if (!UseHalfFloatPrecision)
{
var localScale = CachedTransform.localScale;
if (!UseHalfFloatPrecision)
{

networkState.ScaleX = localScale.x;
networkState.ScaleY = localScale.y;
networkState.ScaleZ = localScale.z;
}
else
{
networkState.Scale = localScale;
}
flagStates.MarkChanged(AxialType.Scale, true);
isScaleDirty = true;
networkState.ScaleX = localScale.x;
networkState.ScaleY = localScale.y;
networkState.ScaleZ = localScale.z;
}
else
{
networkState.Scale = localScale;
}
flagStates.MarkChanged(AxialType.Scale, true);
isScaleDirty = true;
}
isDirty |= isPositionDirty || isRotationDirty || isScaleDirty;

if (isDirty)
Expand Down Expand Up @@ -3488,12 +3488,12 @@ private void NonAuthorityFinalizeSynchronization()
child.InternalInitialization();
}
}
else // Otherwise, just run through standard synchronization of this instance
if (!CanCommitToTransform)
{
ApplySynchronization();
InternalInitialization();
}
// Otherwise, just run through standard synchronization of this instance
else if (!CanCommitToTransform)
{
ApplySynchronization();
InternalInitialization();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,19 +967,18 @@ internal void ProcessClientsToDisconnect()
{
return (true, playerPrefabHash.Value);
}
else
if (NetworkManager.NetworkConfig.PlayerPrefab != null)
else if (NetworkManager.NetworkConfig.PlayerPrefab != null)
{
var networkObject = NetworkManager.NetworkConfig.PlayerPrefab.GetComponent<NetworkObject>();
if (networkObject != null)
{
var networkObject = NetworkManager.NetworkConfig.PlayerPrefab.GetComponent<NetworkObject>();
if (networkObject != null)
{
return (true, networkObject.GlobalObjectIdHash);
}
else
{
NetworkManager.Log.Error(new Logging.Context(LogLevel.Error, $"Player prefab {NetworkManager.NetworkConfig.PlayerPrefab.name} has no {nameof(NetworkObject)}!"));
}
return (true, networkObject.GlobalObjectIdHash);
}
else
{
NetworkManager.Log.Error(new Logging.Context(LogLevel.Error, $"Player prefab {NetworkManager.NetworkConfig.PlayerPrefab.name} has no {nameof(NetworkObject)}!"));
}
}
return (false, 0);
}

Expand Down
Loading