Skip to content

Commit b2f5e84

Browse files
fix: dual triggers generating false state transition [MTTB-48] (#2999)
* fix This fixes the issue where a trigger that transitions to a state with a trigger that transitions back to the original state could cause NetworkAnimator to generate a false layer to layer state transition which would not only generate an additional message after the original trigger message, but would cause the non-authority instances to log a warning message. * test - manual This includes additional assets needed to test this fix manually as well as some of the assets included will be used in an integration test. * test Adding test for the dual trigger scenario. * style Adding additional comments about the update.
1 parent cb11580 commit b2f5e84

29 files changed

+5129
-135
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,12 @@ private void CheckForStateChange(int layer)
832832
stateChangeDetected = true;
833833
//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})");
834834
}
835-
else if (!tt.anyState && tt.fullPathHash != m_TransitionHash[layer])
835+
// 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
836+
// 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
837+
// state then we can handle this transition as a non-cross fade state transition between layers.
838+
// 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.
839+
else if (!tt.anyState && tt.fullPathHash != m_TransitionHash[layer] && (!m_DestinationStateToTransitioninfo.ContainsKey(layer) ||
840+
(m_DestinationStateToTransitioninfo.ContainsKey(layer) && m_DestinationStateToTransitioninfo[layer].ContainsKey(nt.fullPathHash))))
836841
{
837842
// first time in this transition for this layer
838843
m_TransitionHash[layer] = tt.fullPathHash;
@@ -841,6 +846,10 @@ private void CheckForStateChange(int layer)
841846
animState.CrossFade = false;
842847
animState.Transition = true;
843848
animState.NormalizedTime = tt.normalizedTime;
849+
if (m_DestinationStateToTransitioninfo.ContainsKey(layer) && m_DestinationStateToTransitioninfo[layer].ContainsKey(nt.fullPathHash))
850+
{
851+
animState.DestinationStateHash = nt.fullPathHash;
852+
}
844853
stateChangeDetected = true;
845854
//Debug.Log($"[Transition] TI-Duration: ({tt.duration}) | TI-Norm: ({tt.normalizedTime}) | From-Hash: ({m_AnimationHash[layer]}) |SI-FPHash: ({st.fullPathHash}) | SI-Norm: ({st.normalizedTime})");
846855
}

testproject/Assets/Tests/Manual/ManualTestsMenu.unity

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
4241
m_UseRadianceAmbientProbe: 0
4342
--- !u!157 &3
4443
LightmapSettings:
@@ -104,7 +103,7 @@ NavMeshSettings:
104103
serializedVersion: 2
105104
m_ObjectHideFlags: 0
106105
m_BuildSettings:
107-
serializedVersion: 2
106+
serializedVersion: 3
108107
agentTypeID: 0
109108
agentRadius: 0.5
110109
agentHeight: 2
@@ -117,7 +116,7 @@ NavMeshSettings:
117116
cellSize: 0.16666667
118117
manualTileSize: 0
119118
tileSize: 256
120-
accuratePlacement: 0
119+
buildHeightMesh: 0
121120
maxJobWorkers: 0
122121
preserveTilesOutsideBounds: 0
123122
debug:
@@ -128,6 +127,7 @@ PrefabInstance:
128127
m_ObjectHideFlags: 0
129128
serializedVersion: 2
130129
m_Modification:
130+
serializedVersion: 3
131131
m_TransformParent: {fileID: 8786710035725353936}
132132
m_Modifications:
133133
- target: {fileID: 2848221156307247792, guid: 3200770c16e3b2b4ebe7f604154faac7,
@@ -247,6 +247,9 @@ PrefabInstance:
247247
objectReference: {fileID: 11400000, guid: 0c59fa26bc04c0f43b7487b42bca86da,
248248
type: 2}
249249
m_RemovedComponents: []
250+
m_RemovedGameObjects: []
251+
m_AddedGameObjects: []
252+
m_AddedComponents: []
250253
m_SourcePrefab: {fileID: 100100000, guid: 3200770c16e3b2b4ebe7f604154faac7, type: 3}
251254
--- !u!224 &742723029 stripped
252255
RectTransform:
@@ -287,7 +290,6 @@ RectTransform:
287290
m_Children:
288291
- {fileID: 2011195074}
289292
m_Father: {fileID: 8786710034940264808}
290-
m_RootOrder: 0
291293
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
292294
m_AnchorMin: {x: 0, y: 0}
293295
m_AnchorMax: {x: 0, y: 0}
@@ -351,7 +353,9 @@ Canvas:
351353
m_OverrideSorting: 0
352354
m_OverridePixelPerfect: 0
353355
m_SortingBucketNormalizedSize: 0
356+
m_VertexColorAlwaysGammaSpace: 0
354357
m_AdditionalShaderChannelsFlag: 0
358+
m_UpdateRectTransformForStandalone: 0
355359
m_SortingLayerID: 360676703
356360
m_SortingOrder: 0
357361
m_TargetDisplay: 0
@@ -386,7 +390,6 @@ RectTransform:
386390
m_ConstrainProportionsScale: 0
387391
m_Children: []
388392
m_Father: {fileID: 1757257345}
389-
m_RootOrder: 0
390393
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
391394
m_AnchorMin: {x: 0, y: 0}
392395
m_AnchorMax: {x: 1, y: 1}
@@ -438,6 +441,7 @@ Transform:
438441
m_PrefabInstance: {fileID: 0}
439442
m_PrefabAsset: {fileID: 0}
440443
m_GameObject: {fileID: 5174272713122024596}
444+
serializedVersion: 2
441445
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
442446
m_LocalPosition: {x: 0, y: 0, z: 0}
443447
m_LocalScale: {x: 1.5825, y: 1.5825, z: 1.5825}
@@ -446,7 +450,6 @@ Transform:
446450
- {fileID: 8786710036096747217}
447451
- {fileID: 8786710035132639495}
448452
m_Father: {fileID: 0}
449-
m_RootOrder: 1
450453
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
451454
--- !u!1 &5174272713122024596
452455
GameObject:
@@ -479,7 +482,6 @@ RectTransform:
479482
- {fileID: 8786710035165842725}
480483
- {fileID: 8786710036090056061}
481484
m_Father: {fileID: 8786710035000454139}
482-
m_RootOrder: 2
483485
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
484486
m_AnchorMin: {x: 0, y: 0}
485487
m_AnchorMax: {x: 1, y: 0}
@@ -612,7 +614,6 @@ RectTransform:
612614
m_ConstrainProportionsScale: 0
613615
m_Children: []
614616
m_Father: {fileID: 8786710035000454139}
615-
m_RootOrder: 0
616617
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
617618
m_AnchorMin: {x: 0, y: 0}
618619
m_AnchorMax: {x: 1, y: 1}
@@ -678,13 +679,13 @@ Transform:
678679
m_PrefabInstance: {fileID: 0}
679680
m_PrefabAsset: {fileID: 0}
680681
m_GameObject: {fileID: 8786710034828175749}
682+
serializedVersion: 2
681683
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
682684
m_LocalPosition: {x: 627.83386, y: 406.0025, z: -3.938301}
683685
m_LocalScale: {x: 1.5825, y: 1.5825, z: 1.5825}
684686
m_ConstrainProportionsScale: 0
685687
m_Children: []
686688
m_Father: {fileID: 0}
687-
m_RootOrder: 0
688689
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
689690
--- !u!114 &8786710034828175754
690691
MonoBehaviour:
@@ -790,7 +791,6 @@ RectTransform:
790791
m_ConstrainProportionsScale: 0
791792
m_Children: []
792793
m_Father: {fileID: 8786710036075228519}
793-
m_RootOrder: 0
794794
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
795795
m_AnchorMin: {x: 0, y: 0}
796796
m_AnchorMax: {x: 1, y: 0.2}
@@ -828,7 +828,6 @@ RectTransform:
828828
m_ConstrainProportionsScale: 0
829829
m_Children: []
830830
m_Father: {fileID: 8786710035450761404}
831-
m_RootOrder: 2
832831
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
833832
m_AnchorMin: {x: 0, y: 0}
834833
m_AnchorMax: {x: 1, y: 1}
@@ -884,6 +883,7 @@ Transform:
884883
m_PrefabInstance: {fileID: 0}
885884
m_PrefabAsset: {fileID: 0}
886885
m_GameObject: {fileID: 8786710034940264811}
886+
serializedVersion: 2
887887
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
888888
m_LocalPosition: {x: 0, y: 0, z: 0}
889889
m_LocalScale: {x: 1.5825, y: 1.5825, z: 1.5825}
@@ -892,7 +892,6 @@ Transform:
892892
- {fileID: 1757257345}
893893
- {fileID: 8786710035725353936}
894894
m_Father: {fileID: 0}
895-
m_RootOrder: 2
896895
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
897896
--- !u!1 &8786710034940264811
898897
GameObject:
@@ -924,6 +923,7 @@ MonoBehaviour:
924923
m_Name:
925924
m_EditorClassIdentifier:
926925
m_SceneMenus:
926+
- {fileID: 11400000, guid: f2b30a19875731846a69d285dd4700ac, type: 2}
927927
- {fileID: 11400000, guid: 2c0ff1138526d4041a875c84f7114513, type: 2}
928928
- {fileID: 11400000, guid: 5971e25d82220f448be7385f5d71ece9, type: 2}
929929
- {fileID: 11400000, guid: 17de05ff09d39df47a6bc85ab38dca2f, type: 2}
@@ -1062,7 +1062,6 @@ RectTransform:
10621062
- {fileID: 8786710036761675970}
10631063
- {fileID: 8786710034798366468}
10641064
m_Father: {fileID: 8786710035725353936}
1065-
m_RootOrder: 1
10661065
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
10671066
m_AnchorMin: {x: 0.5, y: 0.5}
10681067
m_AnchorMax: {x: 0.5, y: 0.5}
@@ -1163,13 +1162,13 @@ Transform:
11631162
m_PrefabInstance: {fileID: 0}
11641163
m_PrefabAsset: {fileID: 0}
11651164
m_GameObject: {fileID: 8786710035132639489}
1165+
serializedVersion: 2
11661166
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
11671167
m_LocalPosition: {x: 0, y: 3, z: 0}
11681168
m_LocalScale: {x: 1, y: 1, z: 1}
11691169
m_ConstrainProportionsScale: 0
11701170
m_Children: []
11711171
m_Father: {fileID: 4387492341889194239}
1172-
m_RootOrder: 1
11731172
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
11741173
--- !u!1 &8786710035165842724
11751174
GameObject:
@@ -1204,7 +1203,6 @@ RectTransform:
12041203
m_Children:
12051204
- {fileID: 8786710036154109432}
12061205
m_Father: {fileID: 8786710034798366468}
1207-
m_RootOrder: 0
12081206
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
12091207
m_AnchorMin: {x: 0, y: 0}
12101208
m_AnchorMax: {x: 1, y: 1}
@@ -1331,7 +1329,6 @@ RectTransform:
13311329
m_ConstrainProportionsScale: 0
13321330
m_Children: []
13331331
m_Father: {fileID: 8786710035450761404}
1334-
m_RootOrder: 0
13351332
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
13361333
m_AnchorMin: {x: 0, y: 0}
13371334
m_AnchorMax: {x: 1, y: 1}
@@ -1354,7 +1351,6 @@ RectTransform:
13541351
- {fileID: 8786710035740622621}
13551352
- {fileID: 8786710034910084049}
13561353
m_Father: {fileID: 8786710036154109432}
1357-
m_RootOrder: 0
13581354
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
13591355
m_AnchorMin: {x: 0, y: 0.5}
13601356
m_AnchorMax: {x: 1, y: 0.5}
@@ -1480,7 +1476,6 @@ RectTransform:
14801476
- {fileID: 8786710036691323753}
14811477
- {fileID: 8786710036003025139}
14821478
m_Father: {fileID: 8786710034940264808}
1483-
m_RootOrder: 1
14841479
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
14851480
m_AnchorMin: {x: 0, y: 0}
14861481
m_AnchorMax: {x: 0, y: 0}
@@ -1527,7 +1522,9 @@ Canvas:
15271522
m_OverrideSorting: 0
15281523
m_OverridePixelPerfect: 0
15291524
m_SortingBucketNormalizedSize: 0
1525+
m_VertexColorAlwaysGammaSpace: 0
15301526
m_AdditionalShaderChannelsFlag: 0
1527+
m_UpdateRectTransformForStandalone: 0
15311528
m_SortingLayerID: 0
15321529
m_SortingOrder: 0
15331530
m_TargetDisplay: 0
@@ -1600,7 +1597,6 @@ RectTransform:
16001597
m_ConstrainProportionsScale: 0
16011598
m_Children: []
16021599
m_Father: {fileID: 8786710035450761404}
1603-
m_RootOrder: 1
16041600
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
16051601
m_AnchorMin: {x: 0, y: 0.5}
16061602
m_AnchorMax: {x: 0, y: 0.5}
@@ -1726,7 +1722,6 @@ RectTransform:
17261722
m_Children:
17271723
- {fileID: 8786710036368978967}
17281724
m_Father: {fileID: 8786710035725353936}
1729-
m_RootOrder: 4
17301725
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
17311726
m_AnchorMin: {x: 0.5, y: 0.5}
17321727
m_AnchorMax: {x: 0.5, y: 0.5}
@@ -1771,7 +1766,6 @@ RectTransform:
17711766
m_Children:
17721767
- {fileID: 8786710034868932479}
17731768
m_Father: {fileID: 8786710036090056061}
1774-
m_RootOrder: 0
17751769
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
17761770
m_AnchorMin: {x: 0, y: 0}
17771771
m_AnchorMax: {x: 1, y: 1}
@@ -1898,7 +1892,6 @@ RectTransform:
18981892
m_Children:
18991893
- {fileID: 8786710036075228519}
19001894
m_Father: {fileID: 8786710034798366468}
1901-
m_RootOrder: 1
19021895
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
19031896
m_AnchorMin: {x: 1, y: 0}
19041897
m_AnchorMax: {x: 1, y: 1}
@@ -1919,9 +1912,17 @@ Camera:
19191912
m_projectionMatrixMode: 1
19201913
m_GateFitMode: 2
19211914
m_FOVAxisMode: 0
1915+
m_Iso: 200
1916+
m_ShutterSpeed: 0.005
1917+
m_Aperture: 16
1918+
m_FocusDistance: 10
1919+
m_FocalLength: 50
1920+
m_BladeCount: 5
1921+
m_Curvature: {x: 2, y: 11}
1922+
m_BarrelClipping: 0.25
1923+
m_Anamorphism: 0
19221924
m_SensorSize: {x: 36, y: 24}
19231925
m_LensShift: {x: 0, y: 0}
1924-
m_FocalLength: 50
19251926
m_NormalizedViewPortRect:
19261927
serializedVersion: 2
19271928
x: 0
@@ -1955,13 +1956,13 @@ Transform:
19551956
m_PrefabInstance: {fileID: 0}
19561957
m_PrefabAsset: {fileID: 0}
19571958
m_GameObject: {fileID: 8786710036096747218}
1959+
serializedVersion: 2
19581960
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
19591961
m_LocalPosition: {x: 0, y: 1, z: -10}
19601962
m_LocalScale: {x: 1, y: 1, z: 1}
19611963
m_ConstrainProportionsScale: 0
19621964
m_Children: []
19631965
m_Father: {fileID: 4387492341889194239}
1964-
m_RootOrder: 0
19651966
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
19661967
--- !u!1 &8786710036096747218
19671968
GameObject:
@@ -1994,7 +1995,6 @@ RectTransform:
19941995
m_Children:
19951996
- {fileID: 8786710035450761404}
19961997
m_Father: {fileID: 8786710035165842725}
1997-
m_RootOrder: 0
19981998
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
19991999
m_AnchorMin: {x: 0, y: 1}
20002000
m_AnchorMax: {x: 1, y: 1}
@@ -2090,7 +2090,6 @@ RectTransform:
20902090
m_ConstrainProportionsScale: 0
20912091
m_Children: []
20922092
m_Father: {fileID: 8786710035725353936}
2093-
m_RootOrder: 2
20942093
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
20952094
m_AnchorMin: {x: 0.5, y: 1}
20962095
m_AnchorMax: {x: 0.5, y: 1}
@@ -2170,7 +2169,6 @@ RectTransform:
21702169
m_ConstrainProportionsScale: 0
21712170
m_Children: []
21722171
m_Father: {fileID: 8786710036003025139}
2173-
m_RootOrder: 0
21742172
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
21752173
m_AnchorMin: {x: 0, y: 0}
21762174
m_AnchorMax: {x: 1, y: 1}
@@ -2208,7 +2206,6 @@ RectTransform:
22082206
m_ConstrainProportionsScale: 0
22092207
m_Children: []
22102208
m_Father: {fileID: 8786710035725353936}
2211-
m_RootOrder: 3
22122209
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
22132210
m_AnchorMin: {x: 0.5, y: 1}
22142211
m_AnchorMax: {x: 0.5, y: 1}
@@ -2278,7 +2275,6 @@ RectTransform:
22782275
m_ConstrainProportionsScale: 0
22792276
m_Children: []
22802277
m_Father: {fileID: 8786710035000454139}
2281-
m_RootOrder: 1
22822278
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
22832279
m_AnchorMin: {x: 1, y: 0.5}
22842280
m_AnchorMax: {x: 1, y: 0.5}
@@ -2333,3 +2329,10 @@ GameObject:
23332329
m_NavMeshLayer: 0
23342330
m_StaticEditorFlags: 0
23352331
m_IsActive: 1
2332+
--- !u!1660057539 &9223372036854775807
2333+
SceneRoots:
2334+
m_ObjectHideFlags: 0
2335+
m_Roots:
2336+
- {fileID: 8786710034828175752}
2337+
- {fileID: 4387492341889194239}
2338+
- {fileID: 8786710034940264808}

testproject/Assets/Tests/Manual/NetworkAnimatorTests/AnimationBidirectionalTriggers.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.

0 commit comments

Comments
 (0)