GC FSM - Event-driven, hierarchical finite state machines in blueprint

A version for 4.22 has been submitted and should be available for download shortly.

Thanks you:)

@Unreal-NetFly I forgot to mention that sub state objects can always access the context object using the “Context” variable as explained here. You can use that to re-evaluate the expressions inside the OnTick event of the state object.

Thank you very much for your help.

GCFSM for Unreal 4.22 is now available on the Marketplace. Enjoy!

Hi, do the example projects work with 4.20.3?

Yes. Why are you asking?

I was wondering because the example projects on the website say 4.19.2 required

Yes, the examples project was made for that version if Unreal, but it’s still compatible with later versions. When you open the project, Unreal will ask to “upgrade” the project, of course.

Well, I didn’t realize how much I needed this until I started using it. The event-driven design is especially nice.

One question, though, is there a built-in way to return to the “last state” from states with multiple incoming transitions, or is there a recommended way of achieving this?

[Edit] To elaborate, one thing I’m trying to simplify is a modal game menu, but in a game where the player has multiple possible interaction modes during normal gameplay - e.g., locomotion & dialogue have different UIs and input profiles, and I’d like the user to be able to return to whatever the last mode was after exiting the game menu.

One way I can think of is to store the last state name as a variable, then use a switch on exiting the game menu to return to that state. Another might be to implement the game menu mode as a substate in each of the normal interaction-mode states. Are there others?

Thanks! :slight_smile:

I am really sorry, but unfortunately there is no built-in way to achieve that. Once a state is exited, the FSM completely loses memory of it, so there’s no easy way to retrieve that information in the new state. If you are using Implementation States in your project, you could create your own class derived from CGFSMState and store the name of the state in one of the Context’s variables in OnExit. Then you can derive all your implementation classes from that class. By doing this, each state will know the name of the last state that was exited. I don’t know if that may help you.

Ok, thanks for the response - will explore my options :slight_smile:

I ended up creating a base FSM class with a nested state machine that switches between doing nothing and the “from any state” behavior (in this case, a pause menu), then using that as the parent for my main interaction modes, so that every interaction mode can be “interrupted” by the modal menu and then return to its normal operation when it exits the modal menu substate. Seems to work fine so far. Great plugin!

That is very clever. Thanks for the use case, it seems very legitimate. The best tool to address this scenario would be to add support for a feature like the “history pseudostate” in UML. I’ll add it to my todo list.

Hello gamecentric,

I have an issue when triggering 2 events in the same frame, when the 1st one causes transition to submachine state and the 2nd one should affect state within submachine itself but ignored instead. AFAIU the 2nd event should be processed only after the 1st transition is completed. Here is an extract from the documentation:

Am I missing something in setup? For now I’ve just avoided using submachine.
Thanks in advance!

Your expectation is correct. The second event should be processed by the new state as described in the documentation. Of course, I may have made a mistake and you might have encountered a bug, but I’m pretty sure this case should be covered. Please try the following:

  1. Check that the order of the events is correct. If the second event arrives before you can fix the problem by adding the second event as a “deferred” event in the initial state
  2. Check the policies on the TriggerEvent (as described here)
  3. Enable the visual logger (described here) and set the level to “Very Verbose”, you should get a glimpse of what exactly is happening in your FSM

Do you have any suggestions on how to restore states on game load? I think a “Set State” function might be too easily abused, but I don’t know enough about saving/reloading to know what other options there might be…

Restoring a state is something that needs to be designed carefully. Most of the machinery is already in place, since I could re-use the same technique I’m using to replicate FSMs over the network. However, restoring deep sub-FSMs might still be a challenge. I will need to think about that.

Ok, thanks - I just wanted to make sure there wasn’t something built-in before attempting to come up with my own solution.

  1. Yep, order is correct, started from this :slight_smile:
  2. Tried this, no result as well
  3. Seems like event (“NPCTurn”) is ignored by submachine root node. Then, if I add event as deferred to Combat state node it will be “deferred” instead of “ignored” according to logs but won’t trigger transition as well.

Full minimal log:



LogGCFSM (Log) FSM Adventure: started (non-replicated)
LogGCFSM (Log) FSM Adventure: enters state Traveling, class AdventureState_Traveling_C

LogGCFSM (VeryVerbose) FSM Adventure (in state Traveling, class AdventureState_Traveling_C): event ToCombat queued (0 matching events discarded from queue)
LogGCFSM (VeryVerbose) FSM Adventure (in state Traveling, class AdventureState_Traveling_C): event NPCTurn queued (0 matching events discarded from queue)

LogGCFSM (Verbose) FSM Adventure (in state Traveling, class AdventureState_Traveling_C): event ToCombat executes a transition
LogGCFSM (Log) FSM Adventure: exits state Traveling, class AdventureState_Traveling_C
LogGCFSM (Log) FSM Adventure: enters state Combat, submachine Combat
LogGCFSM (Log) FSM Adventure/Combat/Combat: started (non-replicated)
LogGCFSM (Log) FSM Adventure/Combat/Combat: enters state Player's Turn, class AdventureState_Combat_C
LogGCFSM (VeryVerbose) FSM Adventure (in state Combat, submachine Combat): event NPCTurn is ignored

LogGCFSM (VeryVerbose) FSM Adventure (in state Combat, submachine Combat): event Stop queued (0 matching events discarded from queue)
LogGCFSM (VeryVerbose) FSM Adventure/Combat/Combat (in state Player's Turn, class AdventureState_Combat_C): event Stop queued (0 matching events discarded from queue)


Actual SM blueprint: