Skip to content

fix: NetworkTransform dropped packets can cause interpolation stutter [MTT-7551] #2713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
dbc5653
update
NoelStephensUnity Sep 8, 2023
9fd975c
fix
NoelStephensUnity Sep 8, 2023
88823f7
test
NoelStephensUnity Sep 9, 2023
6994c7a
Merge branch 'develop' into fix/networktransform-halffloat-ownership-…
NoelStephensUnity Sep 9, 2023
9da5bff
fix - validation bug
NoelStephensUnity Sep 9, 2023
dbe2012
update
NoelStephensUnity Sep 15, 2023
24bde64
style
NoelStephensUnity Sep 15, 2023
dda3746
test
NoelStephensUnity Sep 16, 2023
0a3b81f
fix
NoelStephensUnity Sep 18, 2023
54b2604
test
NoelStephensUnity Sep 18, 2023
be0e447
update
NoelStephensUnity Sep 18, 2023
2986e71
update
NoelStephensUnity Sep 18, 2023
b0df71f
update
NoelStephensUnity Sep 18, 2023
95cc35d
Merge branch 'develop' into fix/networktransform-dropped-packets-inte…
NoelStephensUnity Oct 10, 2023
87e6923
style
NoelStephensUnity Oct 10, 2023
0d468df
fix
NoelStephensUnity Oct 17, 2023
511b426
test
NoelStephensUnity Oct 17, 2023
10efac7
update and style
NoelStephensUnity Oct 17, 2023
40ad376
style
NoelStephensUnity Oct 17, 2023
70be377
test
NoelStephensUnity Oct 17, 2023
cd399c3
fix
NoelStephensUnity Oct 17, 2023
a3f869d
test
NoelStephensUnity Oct 17, 2023
eae2bc5
revert
NoelStephensUnity Oct 17, 2023
a985c7a
test
NoelStephensUnity Oct 17, 2023
2352410
test
NoelStephensUnity Oct 17, 2023
d605956
update
NoelStephensUnity Oct 18, 2023
6628e90
test
NoelStephensUnity Oct 18, 2023
549eaeb
test
NoelStephensUnity Oct 18, 2023
1e2c09e
update
NoelStephensUnity Oct 18, 2023
93a3528
update
NoelStephensUnity Oct 18, 2023
2958f53
update
NoelStephensUnity Oct 18, 2023
b014488
Merge branch 'develop' into fix/networktransform-dropped-packets-inte…
NoelStephensUnity Oct 27, 2023
81670f7
Update CHANGELOG.md
NoelStephensUnity Oct 27, 2023
6881ad4
Update CHANGELOG.md
NoelStephensUnity Oct 27, 2023
0dd3f65
Merge branch 'develop' into fix/networktransform-dropped-packets-inte…
NoelStephensUnity Oct 28, 2023
d052952
fix
NoelStephensUnity Nov 1, 2023
a4a6977
Merge branch 'develop' into fix/networktransform-dropped-packets-inte…
NoelStephensUnity Nov 1, 2023
c8cf463
Update NetworkTransformStateTests.cs
NoelStephensUnity Nov 2, 2023
021e257
Merge branch 'develop' into fix/networktransform-dropped-packets-inte…
NoelStephensUnity Nov 13, 2023
776314d
update
NoelStephensUnity Nov 13, 2023
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: 4 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ Additional documentation and release notes are available at [Multiplayer Documen

- 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)
- 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)
- 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)
- 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)
- 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)

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

## [1.7.0] - 2023-10-11

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ public struct NetworkDeltaPosition : INetworkSerializable
internal Vector3 DeltaPosition;
internal int NetworkTick;

internal bool SynchronizeBase;

internal bool CollapsedDeltaIntoBase;

/// <summary>
/// The serialization implementation of <see cref="INetworkSerializable"/>
/// </summary>
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
HalfVector3.NetworkSerialize(serializer);
if (SynchronizeBase)
{
serializer.SerializeValue(ref CurrentBasePosition);
}
}

/// <summary>
Expand Down Expand Up @@ -122,6 +130,7 @@ public Vector3 GetDeltaPosition()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void UpdateFrom(ref Vector3 vector3, int networkTick)
{
CollapsedDeltaIntoBase = false;
NetworkTick = networkTick;
DeltaPosition = (vector3 + PrecisionLossDelta) - CurrentBasePosition;
for (int i = 0; i < HalfVector3.Length; i++)
Expand All @@ -136,6 +145,7 @@ public void UpdateFrom(ref Vector3 vector3, int networkTick)
CurrentBasePosition[i] += HalfDeltaConvertedBack[i];
HalfDeltaConvertedBack[i] = 0.0f;
DeltaPosition[i] = 0.0f;
CollapsedDeltaIntoBase = true;
}
}
}
Expand Down Expand Up @@ -164,6 +174,8 @@ public NetworkDeltaPosition(Vector3 vector3, int networkTick, bool3 axisToSynchr
DeltaPosition = Vector3.zero;
HalfDeltaConvertedBack = Vector3.zero;
HalfVector3 = new HalfVector3(vector3, axisToSynchronize);
SynchronizeBase = false;
CollapsedDeltaIntoBase = false;
UpdateFrom(ref vector3, networkTick);
}

Expand Down
567 changes: 452 additions & 115 deletions com.unity.netcode.gameobjects/Components/NetworkTransform.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Unity.Netcode.Editor
[CustomEditor(typeof(NetworkTransform), true)]
public class NetworkTransformEditor : UnityEditor.Editor
{
private SerializedProperty m_UseUnreliableDeltas;
private SerializedProperty m_SyncPositionXProperty;
private SerializedProperty m_SyncPositionYProperty;
private SerializedProperty m_SyncPositionZProperty;
Expand Down Expand Up @@ -39,6 +40,7 @@ public class NetworkTransformEditor : UnityEditor.Editor
/// <inheritdoc/>
public void OnEnable()
{
m_UseUnreliableDeltas = serializedObject.FindProperty(nameof(NetworkTransform.UseUnreliableDeltas));
m_SyncPositionXProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionX));
m_SyncPositionYProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionY));
m_SyncPositionZProperty = serializedObject.FindProperty(nameof(NetworkTransform.SyncPositionZ));
Expand Down Expand Up @@ -129,7 +131,9 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(m_PositionThresholdProperty);
EditorGUILayout.PropertyField(m_RotAngleThresholdProperty);
EditorGUILayout.PropertyField(m_ScaleThresholdProperty);

EditorGUILayout.Space();
EditorGUILayout.LabelField("Delivery", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_UseUnreliableDeltas);
EditorGUILayout.Space();
EditorGUILayout.LabelField("Configurations", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_InLocalSpaceProperty);
Expand Down
Loading