Skip to content

Commit 6efc639

Browse files
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).
1 parent bb9592d commit 6efc639

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,16 @@ private void TryCommitTransform(bool synchronize = false, bool settingState = fa
19581958
m_UseRigidbodyForMotion = m_NetworkRigidbodyInternal.UseRigidBodyForMotion;
19591959
}
19601960
#endif
1961+
// Authority check to assure that UseUnreliableDeltas is not set during runtime while using SwitchTransformSpaceWhenParented.
1962+
if (SwitchTransformSpaceWhenParented && UseUnreliableDeltas && !m_LocalAuthoritativeNetworkState.FlagStates.UnreliableFrameSync)
1963+
{
1964+
if (m_CachedNetworkManager.LogLevel <= LogLevel.Normal)
1965+
{
1966+
Debug.LogWarning($"Reverting {nameof(UseUnreliableDeltas)} back to fals as it cannot be enable while {nameof(SwitchTransformSpaceWhenParented)} is enabled!");
1967+
}
1968+
UseUnreliableDeltas = false;
1969+
}
1970+
19611971
// If the transform has deltas (returns dirty) or if an explicitly set state is pending
19621972
if (m_LocalAuthoritativeNetworkState.ExplicitSet || CheckForStateChange(ref m_LocalAuthoritativeNetworkState, synchronize, forceState: settingState))
19631973
{

0 commit comments

Comments
 (0)