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
15 changes: 15 additions & 0 deletions com.unity.netcode.gameobjects/Editor/InScenePlacedProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Unity.Netcode.Logging;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
Expand All @@ -19,8 +20,22 @@
public int callbackOrder => 0;
public void OnProcessScene(Scene scene, BuildReport report)
{
var log = new ContextualLogger();
log.AddInfo(scene.name, scene.handle);
foreach (var networkObject in FindObjects.FromSceneByType<NetworkObject>(scene, true))
{
if (networkObject.SceneOrigin.IsValid() && networkObject.SceneOrigin.handle != scene.handle)
{
log.Warning(new Context(LogLevel.Developer, $"{nameof(NetworkObject)}'s SceneOrigin doesn't match current scene being processed! Skipping processing.").AddInfo("SceneOrigin", networkObject.SceneOriginHandle).AddNetworkObject(networkObject));
continue;

Check warning on line 30 in com.unity.netcode.gameobjects/Editor/InScenePlacedProcessor.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

com.unity.netcode.gameobjects/Editor/InScenePlacedProcessor.cs#L27-L30

Added lines #L27 - L30 were not covered by tests
}

if (networkObject.HasBeenSpawned)
{
log.Error(new Context(LogLevel.Normal, $"Processing {nameof(NetworkObject)} that has already been spawned! This should not be possible. Skipping processing.").AddNetworkObject(networkObject));
continue;

Check warning on line 36 in com.unity.netcode.gameobjects/Editor/InScenePlacedProcessor.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

com.unity.netcode.gameobjects/Editor/InScenePlacedProcessor.cs#L33-L36

Added lines #L33 - L36 were not covered by tests
}

networkObject.InScenePlaced = true;
}
}
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 @@
{
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)
{

Check warning on line 199 in com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs#L198-L199

Added lines #L198 - L199 were not covered by tests
// If we are no longer a child, then we can remove ourself from this list
s_LastKnownNetworkManagerParents.Remove(networkManager);
}

Check warning on line 202 in com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs#L201-L202

Added lines #L201 - L202 were not covered by tests
}
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
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 @@
}
}
}
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 @@
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();
}

Check warning on line 3496 in com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs#L3493-L3496

Added lines #L3493 - L3496 were not covered by tests
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@
return false;
}

if (networkObject.InScenePlaced)
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
{
NetworkLog.LogWarning($"{NetworkPrefabHandler.PrefabDebugHelper(this)} InScenePlaced {nameof(NetworkObject)} is being registered as a Prefab. This can cause issues!");
}
}

Check warning on line 175 in com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefab.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefab.cs#L170-L175

Added lines #L170 - L175 were not covered by tests

if (networkObject.IsSpawned)
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
{
NetworkLog.LogWarning($"{NetworkPrefabHandler.PrefabDebugHelper(this)} Currently spawned {nameof(NetworkObject)} is being registered as a Prefab. This can cause issues!");
}
}

Check warning on line 183 in com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefab.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefab.cs#L178-L183

Added lines #L178 - L183 were not covered by tests

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,19 +967,18 @@
{
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)}!"));
}
}

Check warning on line 981 in com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs#L978-L981

Added lines #L978 - L981 were not covered by tests
return (false, 0);
}

Expand Down
Loading