UnityHFSM
UnityHFSM copied to clipboard
[Bug] Statemachines inside parallel states don't react to global triggers
Given the following statemachine configuration:
private StateMachine _stateMachine;
void Start()
{
StateMachine a = new();
a.AddState("A");
a.AddState("B");
a.AddTriggerTransition("T", "A", "B");
a.AddTriggerTransition("T", "B", "A");
StateMachine b = new();
b.AddState("C");
b.AddState("D");
b.AddTriggerTransition("T", "C", "D");
b.AddTriggerTransition("T", "D", "C");
_stateMachine = new StateMachine();
_stateMachine.AddState("root", new ParallelStates(a, b));
_stateMachine.Init();
}
Using _statemachine.Trigger("T") will not cause a and b to perform their transitions. This unfortunately makes ParallelStates useless for statemachines that rely heavily on trigger transitions.
This can be fixed by having ParallelStates implement ITriggereable. There is however a potential issue that should be addressed. Say that statemachine "a" has some nested statemachines and statemachine "b" has a transition whose guard checks ActiveStateName of one of those nested machines. An Exception will be thrown if the nested machine is not the active state of its parent machine.