NodeCanvas Forums › Support › Nested FSM never runs onFinish if has AnyState node
If a nested FSM contains an AnyState node, an onFinish transition in the parent FSM will never fire.
The FSM should probably also behave as if there’s no AnyState node, if there’s no possibility of the AnyState ever triggering anything, e.g.
* There are no transitions connected to the AnyState node. (simple to detect)
* The AnyState node is set to no retrigger and it’s trying to transition to the same node.
* The AnyState node is set to no retrigger and the only node it’s connected to has no transitions. (i.e. FSM should finish when the connected node finishes)
IMO, AnyState should be functionally equivalent to attaching the same transition(s) to every state by hand.
i.e. if within a nested FSM Node, A, B and C are ActionNodes connected with some arbitrary transitions, then:
1 2 3 4 |
A -> B AnyState -> C |
Should be equivalent to:
1 2 3 4 5 |
A -> B A -> C B -> C |
However currently the behaviour of these two configurations differs in that only the former will not execute onFinish for the entire FSM Node when C is finished.
I suggest there should be some built-in Action that explicitly finishes the current FSM.
if you’re listening for events in your transitions, one solution to this is doubly-nesting the FSM i.e. Wrap your Nested FSM within another FSM and have any event transitions you’d connect to the AnyState connected to the wrapper FSM instead.
This is made mildly irritating though since the nested wrappers will need to be file assets, rather than bound graphs. Blegh.
Hello,
The condition under which an FSM is considered finished has changed a lot of times in the past since different people expect different things 🙂
I understand what you say though and it mostly makes sense, but because of the many times this behaviour has changed already, I will have to think twice before changing it once again, as so to avoid the unfortunate possibility of breaking existing setups. I will though add a check to see if AnyState has any transitions (your #1 condition), but I don’t see why you would want to have an AnyState without any transitions 🙂
Having said that, here is an action task (that will also be included in the next version) which force finish the current graph whatever it’s type is (BT, FSM, DT).
The action also has a parameter to finish the graph is Success or Failure since some Nested Node types are making use of this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
using ParadoxNotion; using ParadoxNotion.Design; using NodeCanvas.Framework; namespace NodeCanvas.Tasks.Actions{ [Category("✫ Utility")] public class ForceFinishGraph : ActionTask{ public CompactStatus finishStatus = CompactStatus.Success; protected override void OnExecute(){ var graph = ownerSystem as Graph; if (graph != null){ graph.Stop(finishStatus == CompactStatus.Success); } EndAction(graph != null); } } } |
Please let me know if that works for you.
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh
Hi,
I’m wondering how this was supposed to work after the update.
We had several sub-fsm with AnyState nodes, all of them broke following the update because none of them could be exited. With the current setup I have the impression that a sub-fsm with an AnyState simply can’t finish, am I right ?
Hello,
That is (probably unfortunately) correct. An FSM with an AnyState will never finish. You can of course always use a transitional condition to exit the sub-FSM. If this impose a problem for you, I think I could add an option for whether or not an FSM can be “Auto-Finished”, since it seems that different people need different options for their setup in this regard. 🙂
Let me know.
Thanks
Join us on Discord: https://discord.gg/97q2Rjh
Hi,
I did not find any “transitional condition” to exit the FSM, except the one you posted above. Maybe I missed them …
It may be a good idea to add an option, yes, as we are mainly use “Any State” to look for button clicks at a given moment in our game (placement phase in a tactical RPG, for example).
For now I added your custom action and it’s working perfectly though, so no pressure.
Hey,
By “transitional condition”, I mean that you can use conditions on the transitions of the SubFSM-Node in the parent FSM and as such, if a condition becomes true, the transition will take place and thus force stop the SubFSM regardless of which state it currently is.
(But I suppose you already know that 🙂 )
Even so, indeed an option for that would be a nice addition.
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh
IMO, AnyState should be functionally equivalent to attaching the same transition(s) to every state by hand.
I agree, this is the technically correct interpretation of an “any” state 🙂 Are you still planning to implement it this way?
QD
Hello,
It pretty much works this way already. 🙂
What specific implementation, or detail/suggestion from this thread are you referring at? 🙂
Thanks.
Join us on Discord: https://discord.gg/97q2Rjh