Skip to content

Commit 503dd15

Browse files
fix: dual triggers generating false state transition up port (#3008)
* fix This is an up-port of the #2999 NetworkAnimator fix. * test The ci runtime and editor manual tests for this fix. * update Adding changelog entry.
1 parent 57797b7 commit 503dd15

28 files changed

+5031
-80
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1515
### Fixed
1616

1717
- Fixed issue where `FixedStringSerializer<T>` was using `NetworkVariableSerialization<byte>.AreEqual` to determine if two bytes were equal causes an exception to be thrown due to no byte serializer having been defined. (#3009)
18+
- Fixed Issue where a state with dual triggers, inbound and outbound, could cause a false layer to layer state transition message to be sent to non-authority `NetworkAnimator` instances and cause a warning message to be logged. (#3008)
1819
- Fixed issue using collections within `NetworkVariable` where the collection would not detect changes to items or nested items. (#3004)
1920
- Fixed issue where `List`, `Dictionary`, and `HashSet` collections would not uniquely duplicate nested collections. (#3004)
2021
- Fixed issue where `NotAuthorityTarget` would include the service observer in the list of targets to send the RPC to as opposed to excluding the service observer as it should. (#3000)

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,12 @@ private void CheckForStateChange(int layer)
851851
stateChangeDetected = true;
852852
//Debug.Log($"[Cross-Fade] To-Hash: {nt.fullPathHash} | TI-Duration: ({tt.duration}) | TI-Norm: ({tt.normalizedTime}) | From-Hash: ({m_AnimationHash[layer]}) | SI-FPHash: ({st.fullPathHash}) | SI-Norm: ({st.normalizedTime})");
853853
}
854-
else if (!tt.anyState && tt.fullPathHash != m_TransitionHash[layer])
854+
// If we are not transitioned into the "any state" and the animator transition isn't a full path hash (layer to layer) and our pre-built destination state to transition does not contain the
855+
// current layer (i.e. transitioning into a state from another layer) =or= we do contain the layer and the layer contains state to transition to is contained within our pre-built destination
856+
// state then we can handle this transition as a non-cross fade state transition between layers.
857+
// Otherwise, if we don't enter into this then this is a "trigger transition to some state that is now being transitioned back to the Idle state via trigger" or "Dual Triggers" IDLE<-->State.
858+
else if (!tt.anyState && tt.fullPathHash != m_TransitionHash[layer] && (!m_DestinationStateToTransitioninfo.ContainsKey(layer) ||
859+
(m_DestinationStateToTransitioninfo.ContainsKey(layer) && m_DestinationStateToTransitioninfo[layer].ContainsKey(nt.fullPathHash))))
855860
{
856861
// first time in this transition for this layer
857862
m_TransitionHash[layer] = tt.fullPathHash;
@@ -860,6 +865,10 @@ private void CheckForStateChange(int layer)
860865
animState.CrossFade = false;
861866
animState.Transition = true;
862867
animState.NormalizedTime = tt.normalizedTime;
868+
if (m_DestinationStateToTransitioninfo.ContainsKey(layer) && m_DestinationStateToTransitioninfo[layer].ContainsKey(nt.fullPathHash))
869+
{
870+
animState.DestinationStateHash = nt.fullPathHash;
871+
}
863872
stateChangeDetected = true;
864873
//Debug.Log($"[Transition] TI-Duration: ({tt.duration}) | TI-Norm: ({tt.normalizedTime}) | From-Hash: ({m_AnimationHash[layer]}) |SI-FPHash: ({st.fullPathHash}) | SI-Norm: ({st.normalizedTime})");
865874
}

0 commit comments

Comments
 (0)