Skip to content

Commit 28109b4

Browse files
fix: NetworkTransform teleport interpolating from last position on non-authoritative side [NCCBUG-166] (#2110)
* fix NetworkTransform was setting the value of m_Bitset but not resetting the individual bits if there was no deltas. This would result in a gradually increasing message size over time when updating the NetworkTransform. * update migrating the assignment back down below the CanCommitToTransform * fix This resolves the issue where clients were applying every value marked to be synchronized even if the update didn't include specific axis values. * test This includes some fixes to prefabs that hadn't been updated to the more recent changes in NetworkTransform that limited the minimum threshold (i.e. they were set to 0 which causes issues) * fix Since we are now no longer sending the entire transform values, this addition prevents the non-authoritative side from making changes to the transform. * style removing whitespace * update Adding some test adjustments and including rotation to interpolation measurements. * style removing an unused namespace. * style fixing issue with reference to UnityEngine's Object after I removed the system namespace. * fix This includes the adjustments for client authoritative mode to work without sending RPCs. * fix This update fixes the issue where the authoritative side was interpolating when interpolate is enabled. Now, the authoritative side no longer interpolates. * manual test updates These changes make the player client authoritative within the Samples Menu->Additive Scene Loading manual test/sample. * update reverting the change of m_Bitset to an internal. * test update updating test to account for reverting back to the private m_Bitset. * update Migrated the code that updates interpolators with the current value if the axis is not set into the AddInterpolatedState method as opposed to it being in the ApplyInterpolatedNetworkStateToTransform * fix First pass fix for teleporting. * test manual Manual test adjustments (still working on player motion controller from client side) * manual test Adjustments for the teleporting sample/manual test. Still working on the new player cube motion model. * test manual Improved motion model (still could use some more work for client to server side). Now packing data sent from client to host/server. Added UI text that displays whether the instance is a server, host, or client. * update removing debug code * fix This fixes the last issues with teleporting and the updated player motion model. * fix Cleaning up how we handle transitioning to and from global and local space. Minor adjustment to the validation test to assure the range of error being tested on the client side is the same as the delta position threshold range. * update Removing the NetworkTransformState Position, Rotation, and Scale since we are only sending the values that changed (i.e. if the x-axis of position was the only thing that was set and NetworkTransformState.Position was used, then the Y and Z axial values would be invalid). * fix removing code block no longer needed. * style removing a comment that was no longer needed. * update applying suggested changes * update replacing the GetReplicatedNetworkState() method with a getter ReplicatedNetworkState property. * update This is a new approach: - Make in-between state updates additive - Clear our state's Bitset value and prepare to capture any deltas for the next network tick period. * update Realized since we are back to additive (per network tick), we can now remove the non-authoritative interpolation work around for not having all values that changed within the associated NetworkTransformState's network tick period. * update Disposing the NetworkVariables when the NetworkTransform is destroyed. * update Suggestion updates and comment fixes. * style adding Sam's comment. * style updated comment to include what we are preserving. * update Removing the ApplyTransformValues and SetTransformValues as they are no longer needed. Also, removing the associated properties. * Test Manual Updates to manual test related assets and scripts. Removed the "make a pooled object invisible to hide the teleport interpolation issue" hack that would disable the render mesh when despawned and enable it shortly after it is spawned. Increased tick rate to 32 in the additive scene loading test. Fixing white space issues. * update Removing the unused serverTime addition as well. * update Renamed ApplyInterpolatedNetworkStateToTransform to ApplyAuthoritativeState. (It didn't make sense if interpolation is disabled) * tests update This includes an updated NetworkTransformTests that tests both authority types while running in Server and Host modes. This includes some updates to naming for easier identification of what each test does (in test runner and in code). * Update Minor adjustment where we don't need to send a local properties over the stack via parameters. * test Added interpolate enable/disable values to all tests. Now, all NetworkTranaformTests are done with interpolation enabled and disabled. * fix and update Fixed another issue that was exposed while cleaning up the code base. Was able to remove even more of the code added previously. Some clean up as well as making one additional method private as opposed to protected to prevent us from having to release a minor version vs patch. Also, ApplyTransformToNetworkState, and ApplyTransformToNetworkStateWithInfo only return if the state is dirty (the rest can be determined from within the state itself). ApplyLocalNetworkState, used for integration tests, now just returns the NetworkTransformState. * fix This fixes the issue with the memory leak message in the editor NetworkTimeTests (very odd this fixed the issue). * test manual Switched over to an owner authoritative NetworkTransform that also includes the playermovement. Adjusted the PlayerCube NetworkPrefab and minor adjustment to the CollideTeleporter. * update updating the changelog * fix Found a minor logic issue in ApplyTransformToNetworkStateWithInfo where the state dirty flag could be reset before end of the current network tick. This could result in state being carried forward into the next network tick. This resolves that issue. * update Minor adjustment to how we handle applying a rotation measurement on the non-authoritative side. Removed a property not being used outside of a single method and added additional comments to the PlayerMovement component. * update This update includes the final changes required in order to support the previous NetworkTransform model where it was always server authoritative and client owners could direct/apply state via internal RPCs. This also includes the ability for a server to apply/dictate state when running in client owner authority mode. This includes updates to the NetworkTransform tests that validate all of these updates and increase the amount of coverage for NetworkTransform. * style moving new private m_ClientRpcParams and m_ClientIds up to the rest of the property declarations. Adjusting comment * test manual Minor adjustments for the random player movers. Applying the server authoritative player prefab back to be the default for the additive scene sample (this makes it easier to compare to main branch). * style removing a no longer needed comment. adding note about future clean up for NetworkTransform. * style fixed spelling issue * style removing left over comment and spelling * style removing legacy/unused namespaces * update realized our CommitLocallyAndReplicate method was serving no purpose at this point. added the assignment of NetworkTransformState to the ReplicatedNetworkState within TryCommit and removed CommitLocallyAndReplicate. * update removing legacy check for TryCommitTransformToServer that is no longer needed. * update removing m_Transform (no purpose for it) Fixing minor grammar issue with a comment * test manual update removing additional IsOwner check. * revert reverting the changes I made to the editor test NetworkTimeTests as I just had Yamato crash again in a different area in NetworkTimeTests with the same memory leak error. * style replacing LF/CR * Style Improving comments
1 parent 7b6bcc6 commit 28109b4

28 files changed

+4712
-764
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Additional documentation and release notes are available at [Multiplayer Documen
1818
### Fixed
1919

2020
- Fixed an issue where reading/writing more than 8 bits at a time with BitReader/BitWriter would write/read from the wrong place, returning and incorrect result. (#2130)
21+
- Fixed issue with the internal `NetworkTransformState.m_Bitset` flag not getting cleared upon the next tick advancement. (#2110)
22+
- Fixed interpolation issue with `NetworkTransform.Teleport`. (#2110)
23+
- Fixed issue where the authoritative side was interpolating its transform. (#2110)
2124
- Fixed Owner-written NetworkVariable infinitely write themselves (#2109)
2225
- Fixed NetworkList issue that showed when inserting at the very end of a NetworkList (#2099)
2326
- Fixed issue where a client owner of a `NetworkVariable` with both owner read and write permissions would not update the server side when changed. (#2097)

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

Lines changed: 447 additions & 264 deletions
Large diffs are not rendered by default.

com.unity.netcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkTransformTests.cs

Lines changed: 439 additions & 149 deletions
Large diffs are not rendered by default.

com.unity.netcode.gameobjects/Tests/Runtime/TransformInterpolationTests.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,19 @@ namespace Unity.Netcode.RuntimeTests
1010
{
1111
public class TransformInterpolationObject : NetworkBehaviour
1212
{
13+
// Set the minimum threshold which we will use as our margin of error
14+
public const float MinThreshold = 0.001f;
15+
1316
public bool CheckPosition;
1417
public bool IsMoving;
1518
public bool IsFixed;
1619

1720
private void Update()
1821
{
19-
// Since the local position is transformed from local to global and vice-versa on the server and client
20-
// it may accumulate some error. We allow an error of 0.01 over the range of 1000 used in this test.
21-
// This requires precision to 5 digits, so it doesn't weaken the test, while preventing spurious failures
22-
const float maxRoundingError = 0.01f;
23-
2422
// Check the position of the nested object on the client
2523
if (CheckPosition)
2624
{
27-
if (transform.position.y < -maxRoundingError || transform.position.y > 100.0f + maxRoundingError)
25+
if (transform.position.y < -MinThreshold || transform.position.y > 100.0f + MinThreshold)
2826
{
2927
Debug.LogError($"Interpolation failure. transform.position.y is {transform.position.y}. Should be between 0.0 and 100.0");
3028
}
@@ -65,7 +63,8 @@ public class TransformInterpolationTests : NetcodeIntegrationTest
6563
protected override void OnServerAndClientsCreated()
6664
{
6765
m_PrefabToSpawn = CreateNetworkObjectPrefab("InterpTestObject");
68-
m_PrefabToSpawn.AddComponent<NetworkTransform>();
66+
var networkTransform = m_PrefabToSpawn.AddComponent<NetworkTransform>();
67+
networkTransform.PositionThreshold = TransformInterpolationObject.MinThreshold;
6968
m_PrefabToSpawn.AddComponent<TransformInterpolationObject>();
7069
}
7170

@@ -85,8 +84,6 @@ private IEnumerator RefreshNetworkObjects()
8584
m_SpawnedObjectOnClient = s_GlobalNetworkObjects[clientId][m_SpawnedAsNetworkObject.NetworkObjectId];
8685
// make sure the objects are set with the right network manager
8786
m_SpawnedObjectOnClient.NetworkManagerOwner = m_ClientNetworkManagers[0];
88-
89-
9087
}
9188

9289
[UnityTest]

testproject/Assets/Prefabs/ObjectToOverride-VariantBlueCylinder.prefab

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,10 @@ PrefabInstance:
8282
propertyPath: m_LocalEulerAnglesHint.z
8383
value: 0
8484
objectReference: {fileID: 0}
85+
- target: {fileID: 4600632750638426092, guid: 29cabf623d47bb345a9bb4140e4397d7,
86+
type: 3}
87+
propertyPath: PositionThreshold
88+
value: 0.01
89+
objectReference: {fileID: 0}
8590
m_RemovedComponents: []
8691
m_SourcePrefab: {fileID: 100100000, guid: 29cabf623d47bb345a9bb4140e4397d7, type: 3}

testproject/Assets/Prefabs/Player.prefab

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ Transform:
3434
m_PrefabAsset: {fileID: 0}
3535
m_GameObject: {fileID: 4079352819444256614}
3636
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
37-
m_LocalPosition: {x: 5, y: 0.625, z: 5}
37+
m_LocalPosition: {x: 0, y: 0.55, z: 0}
3838
m_LocalScale: {x: 1.25, y: 1.25, z: 1.25}
39+
m_ConstrainProportionsScale: 0
3940
m_Children:
4041
- {fileID: 3519470446676406143}
4142
m_Father: {fileID: 0}
@@ -62,12 +63,11 @@ MonoBehaviour:
6263
SyncScaleX: 1
6364
SyncScaleY: 1
6465
SyncScaleZ: 1
65-
PositionThreshold: 0
66-
RotAngleThreshold: 0
67-
ScaleThreshold: 0
66+
PositionThreshold: 0.01
67+
RotAngleThreshold: 0.01
68+
ScaleThreshold: 0.01
6869
InLocalSpace: 0
6970
Interpolate: 1
70-
FixedSendsPerSecond: 15
7171
--- !u!114 &-3775814466963834669
7272
MonoBehaviour:
7373
m_ObjectHideFlags: 0
@@ -103,6 +103,7 @@ MeshRenderer:
103103
m_CastShadows: 1
104104
m_ReceiveShadows: 1
105105
m_DynamicOccludee: 1
106+
m_StaticShadowCaster: 0
106107
m_MotionVectors: 1
107108
m_LightProbeUsage: 1
108109
m_ReflectionProbeUsage: 1
@@ -239,6 +240,7 @@ Transform:
239240
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
240241
m_LocalPosition: {x: 0, y: 1.045, z: 0}
241242
m_LocalScale: {x: 1, y: 1, z: 1}
243+
m_ConstrainProportionsScale: 0
242244
m_Children: []
243245
m_Father: {fileID: 4079352819444256611}
244246
m_RootOrder: 0
@@ -262,6 +264,7 @@ MeshRenderer:
262264
m_CastShadows: 1
263265
m_ReceiveShadows: 1
264266
m_DynamicOccludee: 1
267+
m_StaticShadowCaster: 0
265268
m_MotionVectors: 1
266269
m_LightProbeUsage: 1
267270
m_ReflectionProbeUsage: 1

testproject/Assets/Prefabs/PlayerCube.prefab

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ GameObject:
1818
- component: {fileID: 8685790303553767876}
1919
- component: {fileID: 3809075828520557319}
2020
- component: {fileID: 7138389085065872747}
21-
- component: {fileID: 8585540885791567915}
2221
- component: {fileID: 2744080254494315543}
2322
m_Layer: 0
2423
m_Name: PlayerCube
@@ -37,6 +36,7 @@ Transform:
3736
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
3837
m_LocalPosition: {x: 0, y: 0.5, z: 0}
3938
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
39+
m_ConstrainProportionsScale: 0
4040
m_Children: []
4141
m_Father: {fileID: 0}
4242
m_RootOrder: 0
@@ -49,14 +49,14 @@ Rigidbody:
4949
m_PrefabAsset: {fileID: 0}
5050
m_GameObject: {fileID: 8685790303553767886}
5151
serializedVersion: 2
52-
m_Mass: 1
53-
m_Drag: 0
54-
m_AngularDrag: 0.05
52+
m_Mass: 2
53+
m_Drag: 0.05
54+
m_AngularDrag: 0.02
5555
m_UseGravity: 1
5656
m_IsKinematic: 1
57-
m_Interpolate: 0
57+
m_Interpolate: 1
5858
m_Constraints: 80
59-
m_CollisionDetection: 0
59+
m_CollisionDetection: 2
6060
--- !u!65 &8685790303553767873
6161
BoxCollider:
6262
m_ObjectHideFlags: 0
@@ -89,6 +89,7 @@ MeshRenderer:
8989
m_CastShadows: 1
9090
m_ReceiveShadows: 1
9191
m_DynamicOccludee: 1
92+
m_StaticShadowCaster: 0
9293
m_MotionVectors: 1
9394
m_LightProbeUsage: 1
9495
m_ReflectionProbeUsage: 1
@@ -127,9 +128,10 @@ LineRenderer:
127128
m_PrefabAsset: {fileID: 0}
128129
m_GameObject: {fileID: 8685790303553767886}
129130
m_Enabled: 1
130-
m_CastShadows: 1
131-
m_ReceiveShadows: 1
131+
m_CastShadows: 0
132+
m_ReceiveShadows: 0
132133
m_DynamicOccludee: 1
134+
m_StaticShadowCaster: 0
133135
m_MotionVectors: 0
134136
m_LightProbeUsage: 0
135137
m_ReflectionProbeUsage: 0
@@ -138,7 +140,7 @@ LineRenderer:
138140
m_RenderingLayerMask: 1
139141
m_RendererPriority: 0
140142
m_Materials:
141-
- {fileID: 0}
143+
- {fileID: 2100000, guid: 712559e4bd05f1942a8fd4bfa4e10c56, type: 2}
142144
m_StaticBatchInfo:
143145
firstSubMesh: 0
144146
subMeshCount: 0
@@ -182,16 +184,16 @@ LineRenderer:
182184
m_RotationOrder: 4
183185
colorGradient:
184186
serializedVersion: 2
185-
key0: {r: 0.73333335, g: 0.7137255, b: 0.6666667, a: 1}
186-
key1: {r: 1, g: 1, b: 1, a: 1}
187-
key2: {r: 1, g: 1, b: 1, a: 0}
187+
key0: {r: 0.30566037, g: 0.90742147, b: 1, a: 1}
188+
key1: {r: 0.28166604, g: 0.8183648, b: 0.8679245, a: 1}
189+
key2: {r: 0.0391598, g: 0.9433962, b: 0.89236206, a: 0}
188190
key3: {r: 0, g: 0, b: 0, a: 0}
189191
key4: {r: 0, g: 0, b: 0, a: 0}
190192
key5: {r: 0, g: 0, b: 0, a: 0}
191193
key6: {r: 0, g: 0, b: 0, a: 0}
192194
key7: {r: 0, g: 0, b: 0, a: 0}
193195
ctime0: 0
194-
ctime1: 25443
196+
ctime1: 26021
195197
ctime2: 65535
196198
ctime3: 0
197199
ctime4: 0
@@ -206,15 +208,15 @@ LineRenderer:
206208
atime5: 0
207209
atime6: 0
208210
atime7: 0
209-
m_Mode: 0
211+
m_Mode: 1
210212
m_NumColorKeys: 3
211213
m_NumAlphaKeys: 2
212214
numCornerVertices: 0
213215
numCapVertices: 0
214216
alignment: 0
215217
textureMode: 0
216-
shadowBias: 0.5
217-
generateLightingData: 0
218+
shadowBias: 1
219+
generateLightingData: 1
218220
m_UseWorldSpace: 1
219221
m_Loop: 0
220222
--- !u!114 &947981134
@@ -245,8 +247,22 @@ MonoBehaviour:
245247
m_Script: {fileID: 11500000, guid: 82b41b172a31546ffba450f1418f4e69, type: 3}
246248
m_Name:
247249
m_EditorClassIdentifier:
248-
m_Speed: 10
249-
m_RotSpeed: 2
250+
SyncPositionX: 1
251+
SyncPositionY: 1
252+
SyncPositionZ: 1
253+
SyncRotAngleX: 0
254+
SyncRotAngleY: 1
255+
SyncRotAngleZ: 0
256+
SyncScaleX: 0
257+
SyncScaleY: 0
258+
SyncScaleZ: 0
259+
PositionThreshold: 0.001
260+
RotAngleThreshold: 0.01
261+
ScaleThreshold: 0.01
262+
InLocalSpace: 0
263+
Interpolate: 1
264+
Speed: 7
265+
RotSpeed: 2
250266
--- !u!114 &3809075828520557319
251267
MonoBehaviour:
252268
m_ObjectHideFlags: 0
@@ -271,34 +287,7 @@ MonoBehaviour:
271287
m_Script: {fileID: 11500000, guid: 3e34656ebae784afca7d1f7f6dc18580, type: 3}
272288
m_Name:
273289
m_EditorClassIdentifier:
274-
Range: 10
275-
--- !u!114 &8585540885791567915
276-
MonoBehaviour:
277-
m_ObjectHideFlags: 0
278-
m_CorrespondingSourceObject: {fileID: 0}
279-
m_PrefabInstance: {fileID: 0}
280-
m_PrefabAsset: {fileID: 0}
281-
m_GameObject: {fileID: 8685790303553767886}
282-
m_Enabled: 1
283-
m_EditorHideFlags: 0
284-
m_Script: {fileID: 11500000, guid: 54c9647dc784a46bca664910f182491e, type: 3}
285-
m_Name:
286-
m_EditorClassIdentifier:
287-
SyncPositionX: 1
288-
SyncPositionY: 1
289-
SyncPositionZ: 1
290-
SyncRotAngleX: 1
291-
SyncRotAngleY: 1
292-
SyncRotAngleZ: 1
293-
SyncScaleX: 1
294-
SyncScaleY: 1
295-
SyncScaleZ: 1
296-
PositionThreshold: 0
297-
RotAngleThreshold: 0
298-
ScaleThreshold: 0
299-
InLocalSpace: 0
300-
Interpolate: 1
301-
FixedSendsPerSecond: 30
290+
Range: 3
302291
--- !u!114 &2744080254494315543
303292
MonoBehaviour:
304293
m_ObjectHideFlags: 0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: 39a16938ffb5cd846a9f6df7a686a9c4, type: 3}
13+
m_Name: Teleporting
14+
m_EditorClassIdentifier:
15+
SceneToReference: {fileID: 102900000, guid: efa247d1f78ca694f8d2dcb5672e8f8b, type: 3}
16+
m_IncludedScenes: []
17+
m_DisplayName: Teleporting
18+
m_ReferencedScenes:
19+
- TeleportSample

testproject/Assets/References/Scene/Teleporting.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testproject/Assets/Samples/SamplesMenu.unity

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2523,8 +2523,9 @@ MonoBehaviour:
25232523
m_Name:
25242524
m_EditorClassIdentifier:
25252525
m_SceneMenus:
2526-
- {fileID: 11400000, guid: 7fdc32fee173cca45a4601ba234954d0, type: 2}
2526+
- {fileID: 11400000, guid: 0509eb053ce4ef749afd8495f13128f1, type: 2}
25272527
- {fileID: 11400000, guid: 9a8d9296fb33f794f95514bf38de3cf9, type: 2}
2528+
- {fileID: 11400000, guid: 7fdc32fee173cca45a4601ba234954d0, type: 2}
25282529
- {fileID: 11400000, guid: 21aae92071ad50448a45b013d8346639, type: 2}
25292530
- {fileID: 11400000, guid: 660535b6e155b5b4bbede52313fcb32e, type: 2}
25302531
- {fileID: 11400000, guid: d2e34ed37c087154dbd7f89fd463801b, type: 2}

0 commit comments

Comments
 (0)