Skip to content

Commit ac46fa7

Browse files
fix: NetworkTransform synchronize position when half float precision is enabled (#2845)
* fix Edge case fix for half float precision not getting the proper initial base offset. * update adding change log entry * update adding PR number * test updating some of the tests to reduce the verbosity of the debug output.
1 parent 5dcc00c commit ac46fa7

File tree

4 files changed

+44
-36
lines changed

4 files changed

+44
-36
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2020

2121
### Fixed
2222

23+
- Fixed issue where `NetworkTransform` could not properly synchronize its base position when using half float precision. (#2845)
2324
- Fixed issue where the host was not invoking `OnClientDisconnectCallback` for its own local client when internally shutting down. (#2822)
2425
- Fixed issue where NetworkTransform could potentially attempt to "unregister" a named message prior to it being registered. (#2807)
2526
- Fixed issue where in-scene placed `NetworkObject`s with complex nested children `NetworkObject`s (more than one child in depth) would not synchronize properly if WorldPositionStays was set to true. (#2796)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,7 @@ private bool ShouldSynchronizeHalfFloat(ulong targetClientId)
14241424
/// <param name="targetClientId">the clientId being synchronized (both reading and writing)</param>
14251425
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
14261426
{
1427+
m_CachedNetworkManager = NetworkManager;
14271428
var targetClientId = m_TargetIdBeingSynchronized;
14281429
var synchronizationState = new NetworkTransformState()
14291430
{
@@ -2764,6 +2765,11 @@ public override void OnNetworkSpawn()
27642765
m_CachedNetworkManager = NetworkManager;
27652766

27662767
Initialize();
2768+
2769+
if (CanCommitToTransform && UseHalfFloatPrecision)
2770+
{
2771+
SetState(GetSpaceRelativePosition(), GetSpaceRelativeRotation(), GetScale(), false);
2772+
}
27672773
}
27682774

27692775
/// <inheritdoc/>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ private void AllChildrenLocalTransformValuesMatch(bool useSubChild, ChildrenTran
5656
// We don't assert on timeout here because we want to log this information during PostAllChildrenLocalTransformValuesMatch
5757
WaitForConditionOrTimeOutWithTimeTravel(() => AllInstancesKeptLocalTransformValues(useSubChild));
5858
var success = true;
59-
m_InfoMessage.AppendLine($"[{checkType}][{useSubChild}] Timed out waiting for all children to have the correct local space values:\n");
6059
if (s_GlobalTimeoutHelper.TimedOut)
6160
{
6261
//var waitForMs = new WaitForSeconds(0.001f);
6362
// If we timed out, then wait for a full range of ticks to assure all data has been synchronized before declaring this a failed test.
6463
for (int j = 0; j < m_ServerNetworkManager.NetworkConfig.TickRate; j++)
6564
{
65+
m_InfoMessage.Clear();
66+
m_InfoMessage.AppendLine($"[{checkType}][{useSubChild}] Timed out waiting for all children to have the correct local space values:\n");
6667
var instances = useSubChild ? ChildObjectComponent.SubInstances : ChildObjectComponent.Instances;
6768
success = PostAllChildrenLocalTransformValuesMatch(useSubChild);
6869
TimeTravel(0.001f);

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ public void AssertArraysDoNotMatch<T>(ref NativeArray<T> a, ref NativeArray<T> b
12131213

12141214
private void TestValueTypeNativeArray<T>(NativeArray<T> testValue, NativeArray<T> changedValue) where T : unmanaged
12151215
{
1216-
Debug.Log($"Changing {ArrayStr(testValue)} to {ArrayStr(changedValue)}");
1216+
VerboseDebug($"Changing {ArrayStr(testValue)} to {ArrayStr(changedValue)}");
12171217
var serverVariable = new NetworkVariable<NativeArray<T>>(testValue);
12181218
var clientVariable = new NetworkVariable<NativeArray<T>>(new NativeArray<T>(1, Allocator.Persistent));
12191219
using var writer = new FastBufferWriter(1024, Allocator.Temp, int.MaxValue);
@@ -1280,7 +1280,7 @@ public void AssertListsDoNotMatch<T>(ref List<T> a, ref List<T> b)
12801280

12811281
private void TestList<T>(List<T> testValue, List<T> changedValue)
12821282
{
1283-
Debug.Log($"Changing {ListStr(testValue)} to {ListStr(changedValue)}");
1283+
VerboseDebug($"Changing {ListStr(testValue)} to {ListStr(changedValue)}");
12841284
var serverVariable = new NetworkVariable<List<T>>(testValue);
12851285
var inPlaceList = new List<T>();
12861286
var clientVariable = new NetworkVariable<List<T>>(inPlaceList);
@@ -1344,7 +1344,7 @@ public void AssertSetsDoNotMatch<T>(ref HashSet<T> a, ref HashSet<T> b) where T
13441344

13451345
private void TestHashSet<T>(HashSet<T> testValue, HashSet<T> changedValue) where T : IEquatable<T>
13461346
{
1347-
Debug.Log($"Changing {HashSetStr(testValue)} to {HashSetStr(changedValue)}");
1347+
VerboseDebug($"Changing {HashSetStr(testValue)} to {HashSetStr(changedValue)}");
13481348
var serverVariable = new NetworkVariable<HashSet<T>>(testValue);
13491349
var inPlaceList = new HashSet<T>();
13501350
var clientVariable = new NetworkVariable<HashSet<T>>(inPlaceList);
@@ -1412,7 +1412,7 @@ public void AssertMapsDoNotMatch<TKey, TVal>(ref Dictionary<TKey, TVal> a, ref D
14121412
private void TestDictionary<TKey, TVal>(Dictionary<TKey, TVal> testValue, Dictionary<TKey, TVal> changedValue)
14131413
where TKey : IEquatable<TKey>
14141414
{
1415-
Debug.Log($"Changing {DictionaryStr(testValue)} to {DictionaryStr(changedValue)}");
1415+
VerboseDebug($"Changing {DictionaryStr(testValue)} to {DictionaryStr(changedValue)}");
14161416
var serverVariable = new NetworkVariable<Dictionary<TKey, TVal>>(testValue);
14171417
var inPlaceList = new Dictionary<TKey, TVal>();
14181418
var clientVariable = new NetworkVariable<Dictionary<TKey, TVal>>(inPlaceList);
@@ -1483,7 +1483,7 @@ public void AssertListsDoNotMatch<T>(ref NativeList<T> a, ref NativeList<T> b) w
14831483

14841484
private void TestValueTypeNativeList<T>(NativeList<T> testValue, NativeList<T> changedValue) where T : unmanaged
14851485
{
1486-
Debug.Log($"Changing {NativeListStr(testValue)} to {NativeListStr(changedValue)}");
1486+
VerboseDebug($"Changing {NativeListStr(testValue)} to {NativeListStr(changedValue)}");
14871487
var serverVariable = new NetworkVariable<NativeList<T>>(testValue);
14881488
var inPlaceList = new NativeList<T>(1, Allocator.Temp);
14891489
var clientVariable = new NetworkVariable<NativeList<T>>(inPlaceList);
@@ -1551,7 +1551,7 @@ public void AssertSetsDoNotMatch<T>(ref NativeHashSet<T> a, ref NativeHashSet<T>
15511551

15521552
private void TestValueTypeNativeHashSet<T>(NativeHashSet<T> testValue, NativeHashSet<T> changedValue) where T : unmanaged, IEquatable<T>
15531553
{
1554-
Debug.Log($"Changing {NativeHashSetStr(testValue)} to {NativeHashSetStr(changedValue)}");
1554+
VerboseDebug($"Changing {NativeHashSetStr(testValue)} to {NativeHashSetStr(changedValue)}");
15551555
var serverVariable = new NetworkVariable<NativeHashSet<T>>(testValue);
15561556
var inPlaceList = new NativeHashSet<T>(1, Allocator.Temp);
15571557
var clientVariable = new NetworkVariable<NativeHashSet<T>>(inPlaceList);
@@ -1626,7 +1626,7 @@ private void TestValueTypeNativeHashMap<TKey, TVal>(NativeHashMap<TKey, TVal> te
16261626
where TKey : unmanaged, IEquatable<TKey>
16271627
where TVal : unmanaged
16281628
{
1629-
Debug.Log($"Changing {NativeHashMapStr(testValue)} to {NativeHashMapStr(changedValue)}");
1629+
VerboseDebug($"Changing {NativeHashMapStr(testValue)} to {NativeHashMapStr(changedValue)}");
16301630
var serverVariable = new NetworkVariable<NativeHashMap<TKey, TVal>>(testValue);
16311631
var inPlaceList = new NativeHashMap<TKey, TVal>(1, Allocator.Temp);
16321632
var clientVariable = new NetworkVariable<NativeHashMap<TKey, TVal>>(inPlaceList);
@@ -2169,10 +2169,10 @@ public string ArrayStr<T>(NativeArray<T> arr) where T : unmanaged
21692169
changed2[originalSize + i] = item;
21702170
}
21712171

2172-
Debug.Log($"Original: {ArrayStr(original)}");
2173-
Debug.Log($"Changed: {ArrayStr(changed)}");
2174-
Debug.Log($"Original2: {ArrayStr(original2)}");
2175-
Debug.Log($"Changed2: {ArrayStr(changed2)}");
2172+
VerboseDebug($"Original: {ArrayStr(original)}");
2173+
VerboseDebug($"Changed: {ArrayStr(changed)}");
2174+
VerboseDebug($"Original2: {ArrayStr(original2)}");
2175+
VerboseDebug($"Changed2: {ArrayStr(changed2)}");
21762176
return (original, original2, changed, changed2);
21772177
}
21782178

@@ -2464,10 +2464,10 @@ public string DictionaryStr<TKey, TVal>(Dictionary<TKey, TVal> list)
24642464

24652465
}
24662466

2467-
Debug.Log($"Original: {ListStr(original)}");
2468-
Debug.Log($"Changed: {ListStr(changed)}");
2469-
Debug.Log($"Original2: {ListStr(original2)}");
2470-
Debug.Log($"Changed2: {ListStr(changed2)}");
2467+
VerboseDebug($"Original: {ListStr(original)}");
2468+
VerboseDebug($"Changed: {ListStr(changed)}");
2469+
VerboseDebug($"Original2: {ListStr(original2)}");
2470+
VerboseDebug($"Changed2: {ListStr(changed2)}");
24712471
return (original, original2, changed, changed2);
24722472
}
24732473

@@ -2531,10 +2531,10 @@ public string DictionaryStr<TKey, TVal>(Dictionary<TKey, TVal> list)
25312531
changed2.Add(item);
25322532
}
25332533

2534-
Debug.Log($"Original: {HashSetStr(original)}");
2535-
Debug.Log($"Changed: {HashSetStr(changed)}");
2536-
Debug.Log($"Original2: {HashSetStr(original2)}");
2537-
Debug.Log($"Changed2: {HashSetStr(changed2)}");
2534+
VerboseDebug($"Original: {HashSetStr(original)}");
2535+
VerboseDebug($"Changed: {HashSetStr(changed)}");
2536+
VerboseDebug($"Original2: {HashSetStr(original2)}");
2537+
VerboseDebug($"Changed2: {HashSetStr(changed2)}");
25382538
return (original, original2, changed, changed2);
25392539
}
25402540

@@ -2622,10 +2622,10 @@ public string DictionaryStr<TKey, TVal>(Dictionary<TKey, TVal> list)
26222622
changed2.Add(key, val);
26232623
}
26242624

2625-
Debug.Log($"Original: {DictionaryStr(original)}");
2626-
Debug.Log($"Changed: {DictionaryStr(changed)}");
2627-
Debug.Log($"Original2: {DictionaryStr(original2)}");
2628-
Debug.Log($"Changed2: {DictionaryStr(changed2)}");
2625+
VerboseDebug($"Original: {DictionaryStr(original)}");
2626+
VerboseDebug($"Changed: {DictionaryStr(changed)}");
2627+
VerboseDebug($"Original2: {DictionaryStr(original2)}");
2628+
VerboseDebug($"Changed2: {DictionaryStr(changed2)}");
26292629
return (original, original2, changed, changed2);
26302630
}
26312631

@@ -3911,10 +3911,10 @@ public string NativeHashMapStr<TKey, TVal>(NativeHashMap<TKey, TVal> list)
39113911

39123912
}
39133913

3914-
Debug.Log($"Original: {NativeListStr(original)}");
3915-
Debug.Log($"Changed: {NativeListStr(changed)}");
3916-
Debug.Log($"Original2: {NativeListStr(original2)}");
3917-
Debug.Log($"Changed2: {NativeListStr(changed2)}");
3914+
VerboseDebug($"Original: {NativeListStr(original)}");
3915+
VerboseDebug($"Changed: {NativeListStr(changed)}");
3916+
VerboseDebug($"Original2: {NativeListStr(original2)}");
3917+
VerboseDebug($"Changed2: {NativeListStr(changed2)}");
39183918
return (original, original2, changed, changed2);
39193919
}
39203920

@@ -3978,10 +3978,10 @@ public string NativeHashMapStr<TKey, TVal>(NativeHashMap<TKey, TVal> list)
39783978
changed2.Add(item);
39793979
}
39803980

3981-
Debug.Log($"Original: {NativeHashSetStr(original)}");
3982-
Debug.Log($"Changed: {NativeHashSetStr(changed)}");
3983-
Debug.Log($"Original2: {NativeHashSetStr(original2)}");
3984-
Debug.Log($"Changed2: {NativeHashSetStr(changed2)}");
3981+
VerboseDebug($"Original: {NativeHashSetStr(original)}");
3982+
VerboseDebug($"Changed: {NativeHashSetStr(changed)}");
3983+
VerboseDebug($"Original2: {NativeHashSetStr(original2)}");
3984+
VerboseDebug($"Changed2: {NativeHashSetStr(changed2)}");
39853985
return (original, original2, changed, changed2);
39863986
}
39873987

@@ -4070,10 +4070,10 @@ public string NativeHashMapStr<TKey, TVal>(NativeHashMap<TKey, TVal> list)
40704070
changed2.Add(key, val);
40714071
}
40724072

4073-
Debug.Log($"Original: {NativeHashMapStr(original)}");
4074-
Debug.Log($"Changed: {NativeHashMapStr(changed)}");
4075-
Debug.Log($"Original2: {NativeHashMapStr(original2)}");
4076-
Debug.Log($"Changed2: {NativeHashMapStr(changed2)}");
4073+
VerboseDebug($"Original: {NativeHashMapStr(original)}");
4074+
VerboseDebug($"Changed: {NativeHashMapStr(changed)}");
4075+
VerboseDebug($"Original2: {NativeHashMapStr(original2)}");
4076+
VerboseDebug($"Changed2: {NativeHashMapStr(changed2)}");
40774077
return (original, original2, changed, changed2);
40784078
}
40794079

0 commit comments

Comments
 (0)