It works fine when the ActionTask is assigned to a standalone FSM, but when assigned to a nested FSM it returns the currentStateName from the topmost FSM, is this a bug ? or is there another way to get the currentStateName the same way no matter if the FSM is nested or not ?
The way currentState is designed to work now, is that it returns the State only within the FSM it is called from. Each FSM holds it’s own currentState. Thus ‘agent.behaviour.currentStateName’ will return the root FSM (one assigned in FSMOwner) current State name.
Here is a workaround to get the current state name of the task’s own FSM from within an action/condition task:
1
2
3
4
5
6
7
8
9
10
11
12
publicclassGetCurrentStateName:ActionTask{
publicBBParameter<string>currentState;
protectedoverridevoidOnExecute(){
varmyFSM=(FSM)ownerSystem;//the ownerSystem is the graph which this task is assigned within.
currentState.value=myFSM.currentStateName;
EndAction(true);
}
}
Let me know if that works for you.
I will certainly look after a simple method to get the current state from the FSMOwner regardless of nested or root as well.