Skip to content

Commit d099d64

Browse files
fix: NetworkTransform dropped packets can cause interpolation stutter [MTT-7551] (#2713)
* update Adding OnOwnershipChanged(ulong previous, ulong current) * fix This resolves the issue with client authoritative network transforms and the random "noise" that would occur when transitioning ownership from a remote client back to the host-server. - Latent messages from the client would still be received and processed after ownership changed. - Ownership changed messages would proceed the NetworkTransform initialization state update message. Now ownership changed messages precede the NetworkTransform initialization state update message. - Clients could sometimes have the same network tick value even when the tick event had triggered, which for NetworkDeltaPosition would cause dropped state updates. * test minor adjustment to a test that would fail from time to time due to precision. * Merge branch 'develop' into fix/networktransform-halffloat-ownership-sync * fix - validation bug This is another bug in the validation test suite where removing an override of a virtual method that can still be overridden will throw an API validation error. * update Send deltas unreliable but synchronization and teleporting reliably. * style white space fixes * test Fixing issue with changes that require a NetworkManager to be present. * fix Fixing new issues (due to changes) with position not synchronizing to the target position when half float precision was enabled. * test minor adjustments to account for minor precision delta when quaternion compression is enabled in the NetworkTransformTests.ParentedNetworkTransformTest * update Resolves the api validation issue. * update Updating rotation and scale delta checks when sending unreliable messages. * update Was doing some profiling and found a few low hanging fruit areas that helps improve performance. * style removing whitespace * fix More adjustments to handle sending unreliable deltas. These changes will (when sending unreliable deltas): - Stagger NetworkTransform axial frame synchronization - Axial frame synchronization is sent reliably - Axial frame synchronization is sent only if deltas have been sent (once to assure when an object stops it no longer sends syncs) This also adjusts the "one tick event updates all NetworkTransform authority instances" addition. * test Fixing an issue with precision adjustments for rotation. Adding integration test to validate the handling of dropped packets. * update and style Removing unused namespace. Removing reference to static variable that no longer exists (was for debugging) * style removed whitespaces * test Removing UseUnreliableDeltas when running the TestRotationThresholdDeltaCheck as the synchronization frame could cause this test to fail. * fix Noticed a potential timing related parenting issue where a parented object should be fully synchronized by NetworkTransform (even though it sends transform information when parenting). * test Some additional tweaks to the parenting portion of the NetworkTransform tests. * revert Reverting the parenting adjustment, that was a bad idea. Only reset and update interpolators if interpolation is enabled seems to resolve the earlier issue. * test removing unused methods. adding 100ms latency to the NetworkTransformUTPTests. * test Renaming NetworkTransformUTPTests to NetworkTransformPacketLossTests * update Exposing the UseUnreliableDeltas property and adding UI/UX to provide users a way to disable this via the inspector view. * test Making NetworkTransformTests run with UseUnreliableDeltas disabled to validate this operation mode of NetworkTransform. * test Adding additional wait for added latency. * update adding change log entries. * update Removing some todo statements and finalizing a bit flag to assure non-authoritative instances mirror the authoritative instance's UseUnreliableDeltas settings (i.e. if owner authoritative and ownership changes the same settings should apply). * update Updating change log entry * Update CHANGELOG.md Fixing bad changelog merge * Update CHANGELOG.md adding CR/LF * fix Discovered a long time standing parenting issue with the initial synchronization (while working on something else). The issue involves WorldPositionStays, InLocalSpace, and the initial synchronization. Added comments to describe the adjustments. Basically, when synchronizing, ignore the InLocalSpace setting and only use the WorldPositionStays value to determine which position space to use on the authoritative side only when building the initial synchronization state update. * Update NetworkTransformStateTests.cs Just adjusting the way a test asserts on null based on suggested review feedback. * update minor adjustments to when we need to send a reliable packet when sending unreliable deltas.
1 parent 6096fa9 commit d099d64

File tree

8 files changed

+1474
-127
lines changed

8 files changed

+1474
-127
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ Additional documentation and release notes are available at [Multiplayer Documen
1414

1515
- Fixed a bug where having a class with Rpcs that inherits from a class without Rpcs that inherits from NetworkVariable would cause a compile error. (#2751)
1616
- Fixed issue where `NetworkBehaviour.Synchronize` was not truncating the write buffer if nothing was serialized during `NetworkBehaviour.OnSynchronize` causing an additional 6 bytes to be written per `NetworkBehaviour` component instance. (#2749)
17+
- Fixed issue where a parented in-scene placed NetworkObject would be destroyed upon a client or server exiting a network session but not unloading the original scene in which the NetworkObject was placed. (#2737)
18+
- Fixed issue where during client synchronization and scene loading, when client synchronization or the scene loading mode are set to `LoadSceneMode.Single`, a `CreateObjectMessage` could be received, processed, and the resultant spawned `NetworkObject` could be instantiated in the client's currently active scene that could, towards the end of the client synchronization or loading process, be unloaded and cause the newly created `NetworkObject` to be destroyed (and throw and exception). (#2735)
19+
- Fixed issue where a `NetworkTransform` instance with interpolation enabled would result in wide visual motion gaps (stuttering) under above normal latency conditions and a 1-5% or higher packet are drop rate. (#2713)
1720

1821
### Changed
22+
- Changed `NetworkTransform` authoritative instance tick registration so a single `NetworkTransform` specific tick event update will update all authoritative instances to improve perofmance. (#2713)
1923

2024
## [1.7.0] - 2023-10-11
2125

com.unity.netcode.gameobjects/Components/NetworkDeltaPosition.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@ public struct NetworkDeltaPosition : INetworkSerializable
2323
internal Vector3 DeltaPosition;
2424
internal int NetworkTick;
2525

26+
internal bool SynchronizeBase;
27+
28+
internal bool CollapsedDeltaIntoBase;
29+
2630
/// <summary>
2731
/// The serialization implementation of <see cref="INetworkSerializable"/>
2832
/// </summary>
2933
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
3034
{
3135
HalfVector3.NetworkSerialize(serializer);
36+
if (SynchronizeBase)
37+
{
38+
serializer.SerializeValue(ref CurrentBasePosition);
39+
}
3240
}
3341

3442
/// <summary>
@@ -122,6 +130,7 @@ public Vector3 GetDeltaPosition()
122130
[MethodImpl(MethodImplOptions.AggressiveInlining)]
123131
public void UpdateFrom(ref Vector3 vector3, int networkTick)
124132
{
133+
CollapsedDeltaIntoBase = false;
125134
NetworkTick = networkTick;
126135
DeltaPosition = (vector3 + PrecisionLossDelta) - CurrentBasePosition;
127136
for (int i = 0; i < HalfVector3.Length; i++)
@@ -136,6 +145,7 @@ public void UpdateFrom(ref Vector3 vector3, int networkTick)
136145
CurrentBasePosition[i] += HalfDeltaConvertedBack[i];
137146
HalfDeltaConvertedBack[i] = 0.0f;
138147
DeltaPosition[i] = 0.0f;
148+
CollapsedDeltaIntoBase = true;
139149
}
140150
}
141151
}
@@ -164,6 +174,8 @@ public NetworkDeltaPosition(Vector3 vector3, int networkTick, bool3 axisToSynchr
164174
DeltaPosition = Vector3.zero;
165175
HalfDeltaConvertedBack = Vector3.zero;
166176
HalfVector3 = new HalfVector3(vector3, axisToSynchronize);
177+
SynchronizeBase = false;
178+
CollapsedDeltaIntoBase = false;
167179
UpdateFrom(ref vector3, networkTick);
168180
}
169181

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

Lines changed: 452 additions & 115 deletions
Large diffs are not rendered by default.

com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Unity.Netcode.Editor
1010
[CustomEditor(typeof(NetworkTransform), true)]
1111
public class NetworkTransformEditor : UnityEditor.Editor
1212
{
13+
private SerializedProperty m_UseUnreliableDeltas;
1314
private SerializedProperty m_SyncPositionXProperty;
1415
private SerializedProperty m_SyncPositionYProperty;
1516
private SerializedProperty m_SyncPositionZProperty;
@@ -39,6 +40,7 @@ public class NetworkTransformEditor : UnityEditor.Editor
3940
/// <inheritdoc/>
4041
public void OnEnable()
4142
{
43+
m_UseUnreliableDeltas = serializedObject.FindProperty(nameof(NetworkTransform.UseUnreliableDeltas));
4244
m_SyncPositionXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionX));
4345
m_SyncPositionYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionY));
4446
m_SyncPositionZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionZ));
@@ -129,7 +131,9 @@ public override void OnInspectorGUI()
129131
EditorGUILayout.PropertyField(m_PositionThresholdProperty);
130132
EditorGUILayout.PropertyField(m_RotAngleThresholdProperty);
131133
EditorGUILayout.PropertyField(m_ScaleThresholdProperty);
132-
134+
EditorGUILayout.Space();
135+
EditorGUILayout.LabelField("Delivery", EditorStyles.boldLabel);
136+
EditorGUILayout.PropertyField(m_UseUnreliableDeltas);
133137
EditorGUILayout.Space();
134138
EditorGUILayout.LabelField("Configurations", EditorStyles.boldLabel);
135139
EditorGUILayout.PropertyField(m_InLocalSpaceProperty);

0 commit comments

Comments
 (0)