Skip to content

Commit 23014fe

Browse files
NoelStephensUnitymichalChrobot
authored andcommitted
fix: Prevent UseUnreliableDeltas from being used with SwitchTransformSpaceWhenParented (#3875)
* fix Prevent user from selecting use unreliable deltas when SwitchTransformSpaceWhenParented is enabled (and vice versa). Adding check during runtime to also notify the user that this combination does not work (i.e. missed updates can result in a missed transform update when parenting changes). * update Updating XML API to reflect the changes. * update Updating documentation. * update Adding changelog entry. Removing white space. * update Including the scenario where SwitchTransformSpaceWhenParented was set while UseUnreliableDeltas had already been set. * style Fixing warning message grammar. * update Including NetworkTransform and the name in the warning logged when trying to set one or the other while either one is set.
1 parent ee70c63 commit 23014fe

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

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

1919
### Fixed
2020

21+
- Fixed `NetworkTransform` issue where a user could enable UseUnreliableDeltas while SwitchTransformSpaceWhenParented was also enabled (and vice versa). (#3875)
2122
- Fixed issue where `NetworkVariable` was not properly synchronizing to changes made by the spawn and write authority during `OnNetworkSpawn` and `OnNetworkPostSpawn`. (#3878)
2223
- Fixed issue where `NetworkManager` was not cleaning itself up if an exception was thrown while starting. (#3864)
2324
- Prevented a `NullReferenceException` in `UnityTransport` when using a custom `INetworkStreamDriverConstructor` that doesn't use all the default pipelines and the multiplayer tools package is installed. (#3853)

com.unity.netcode.gameobjects/Documentation~/components/helper/networktransform.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ The following NetworkTransform properties can cause a full state update when cha
7575
- __Use Quaternion Compression__
7676
- __Use Half Float Precision__
7777

78+
> [!NOTE]
79+
> **UseUnreliableDeltas** cannot be enabled if **SwitchTransformSpaceWhenParented** is enabled since **SwitchTransformSpaceWhenParented** requires deltas to be sent reliably.
80+
7881
### Axis to Synchronize
7982

8083
![image](../../images/networktransform/AxisToSynchronize.png)
@@ -180,6 +183,7 @@ To resolve this issue, you can enable the __Switch Transform Space When Parented
180183
Things to consider when using __Switch Transform Space When Parented__:
181184

182185
- This property is synchronized by the authority instance. If you disable it on the authority instance then it will synchronize this adjustment on all non-authority instances.
186+
- This property cannot be enabled when **UseUnreliableDeltas** is enabled as it requires deltas to be sent reliably.
183187
- When using __Switch Transform Space When Parented__, it's best to not make adjustments to the __NetworkTransform.InLocalSpace__ field and let the NetworkTransform handle this for you.
184188
- While you can still change __In Local Space__ directly via script while __Switch Transform Space When Parented__ is enabled, this could impact the end results. It is recommended to not adjust __In Local Space__ when __Switch Transform Space When Parented__ is enabled.
185189

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,45 @@ private void DisplayNetworkTransformProperties()
184184
EditorGUILayout.Space();
185185
EditorGUILayout.LabelField("Delivery", EditorStyles.boldLabel);
186186
EditorGUILayout.PropertyField(m_TickSyncChildren);
187-
EditorGUILayout.PropertyField(m_UseUnreliableDeltas);
187+
// If both are set from a previous configuration, then SwitchTransformSpaceWhenParented takes
188+
// precedence.
189+
if (networkTransform.UseUnreliableDeltas && networkTransform.SwitchTransformSpaceWhenParented)
190+
{
191+
networkTransform.UseUnreliableDeltas = false;
192+
}
193+
GUI.enabled = !networkTransform.SwitchTransformSpaceWhenParented;
194+
if (networkTransform.SwitchTransformSpaceWhenParented)
195+
{
196+
EditorGUILayout.BeginHorizontal();
197+
EditorGUILayout.PropertyField(m_UseUnreliableDeltas);
198+
EditorGUILayout.LabelField($"Cannot use with {nameof(NetworkTransform.SwitchTransformSpaceWhenParented)}.");
199+
EditorGUILayout.EndHorizontal();
200+
}
201+
else
202+
{
203+
EditorGUILayout.PropertyField(m_UseUnreliableDeltas);
204+
}
205+
GUI.enabled = true;
206+
188207
EditorGUILayout.Space();
189208
EditorGUILayout.LabelField("Configurations", EditorStyles.boldLabel);
190-
EditorGUILayout.PropertyField(m_SwitchTransformSpaceWhenParented);
209+
GUI.enabled = !networkTransform.UseUnreliableDeltas;
210+
if (networkTransform.UseUnreliableDeltas)
211+
{
212+
EditorGUILayout.BeginHorizontal();
213+
EditorGUILayout.PropertyField(m_SwitchTransformSpaceWhenParented);
214+
EditorGUILayout.LabelField($"Cannot use with {nameof(NetworkTransform.UseUnreliableDeltas)}.");
215+
EditorGUILayout.EndHorizontal();
216+
}
217+
else
218+
{
219+
EditorGUILayout.PropertyField(m_SwitchTransformSpaceWhenParented);
220+
}
221+
GUI.enabled = true;
191222
if (m_SwitchTransformSpaceWhenParented.boolValue)
192223
{
193224
m_TickSyncChildren.boolValue = true;
225+
networkTransform.UseUnreliableDeltas = false;
194226
}
195227
else
196228
{

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,7 @@ public enum AuthorityModes
13701370
/// are sent using a reliable fragmented sequenced network delivery.
13711371
/// </summary>
13721372
/// <remarks>
1373+
/// Cannot be used when <see cref="SwitchTransformSpaceWhenParented"/> is enabled. <br />
13731374
/// The following more critical state updates are still sent as reliable fragmented sequenced:<br />
13741375
/// <list type="bullet">
13751376
/// <item><description>The initial synchronization state update.</description></item>
@@ -1570,6 +1571,7 @@ internal bool SynchronizeScale
15701571
/// When de-parented: Automatically transitions into world space and coverts any pending interpolation states to the relative local space on non-authority instances.<br />
15711572
/// </summary>
15721573
/// <remarks>
1574+
/// Cannot be used if <see cref="UseUnreliableDeltas"/> is enabled. <br />
15731575
/// Only works with <see cref="NetworkTransform"/> components that are not paired with a <see cref="NetworkRigidbody"/> or <see cref="NetworkRigidbody2D"/> component that is configured to use the rigid body for motion.<br />
15741576
/// <see cref="TickSyncChildren"/> will automatically be set when this is enabled.
15751577
/// This field is auto-synchronized with non-authority clients when changed by the authority instance.
@@ -1958,6 +1960,28 @@ private void TryCommitTransform(bool synchronize = false, bool settingState = fa
19581960
m_UseRigidbodyForMotion = m_NetworkRigidbodyInternal.UseRigidBodyForMotion;
19591961
}
19601962
#endif
1963+
// Authority check to assure that UseUnreliableDeltas is not set during runtime while using SwitchTransformSpaceWhenParented.
1964+
if (SwitchTransformSpaceWhenParented && UseUnreliableDeltas)
1965+
{
1966+
// If we didn't have UseUnreliableDeltas previously set...
1967+
if (!m_LocalAuthoritativeNetworkState.FlagStates.UnreliableFrameSync)
1968+
{
1969+
if (m_CachedNetworkManager.LogLevel <= LogLevel.Normal)
1970+
{
1971+
NetworkLog.LogWarning($"[{nameof(NetworkTransform)}][{name}] Reverting {nameof(UseUnreliableDeltas)} back to false as it cannot be enabled while {nameof(SwitchTransformSpaceWhenParented)} is enabled!");
1972+
}
1973+
UseUnreliableDeltas = false;
1974+
}
1975+
else // Otherwise SwitchTransformSpaceWhenParented has changed while UseUnreliableDeltas was already set.
1976+
{
1977+
if (m_CachedNetworkManager.LogLevel <= LogLevel.Normal)
1978+
{
1979+
NetworkLog.LogWarning($"[{nameof(NetworkTransform)}][{name}] Reverting {nameof(SwitchTransformSpaceWhenParented)} back to false as it cannot be enabled while {nameof(UseUnreliableDeltas)} is enabled!");
1980+
}
1981+
SwitchTransformSpaceWhenParented = false;
1982+
}
1983+
}
1984+
19611985
// If the transform has deltas (returns dirty) or if an explicitly set state is pending
19621986
if (m_LocalAuthoritativeNetworkState.ExplicitSet || CheckForStateChange(ref m_LocalAuthoritativeNetworkState, synchronize, forceState: settingState))
19631987
{

0 commit comments

Comments
 (0)