UFSM: Finite State Machine

I love cleaner nodes :slight_smile:

Update mentioned above have been published by Epic;
Note: those updated nodes are going to break your pin connections from the earlier versions, so reconnecting them is an unfortunate need for this update; but I promise it’s worth it!

Well, so… Due to popular demand I had to take some time and implement this:

On the Details panel of your FSM Component you will be able to define default transitions from State to State, within the FSM / Transition tab.
Those ‘links’ are a place where you can dictate which State comes next without having to deal with any Blueprint code, just type in the name of target next State your FSM is supposed to go after you’re done with current State.
Optionally, when this transition is executed, you can also provide name of a Blueprint Function to be executed exactly the same time such transition happens (in case you want to run some code or validate a transition);
I’m not quite sure why developers requested this a lot, I like to make my own transition functions myself because there I can go crazy and check for anything I want to :stuck_out_tongue:
But I understand how useful it is, so… At the moment it look like this:

One of my Enum Blueprints, I will use this as example for clarity (it’s useful because it’s faster this way, but we can just type the States by hand if we want to):

On the FSM Component, I tell the ‘Enumarator’ field to use this Enum, simple selecting it from dropdown list;
After picking my Enum with State names, let Unreal do its magic:

In this case bellow I am using another Enumerator, the one I use the setup my Character’s movement;
Once States and links are the way I need, I then create an optional call-back function and give it the same name I set in “Function”, right bellow “Next State” field:

Now that I have setup there on Details panel a default transition which says “whenever finished Normal State then go to Jump State”, in Blueprint Graph I don’t care anymore how / when / why the FSM will change its current State from “Normal” to something else.
Since I know that default transition is set to be Jump when Normal exits, now I just call “Finish State” instead of manually telling the FSM to explicitly go to a State I chose based on IFs and ELSEs somewhere in the Blueprint Graph:

This behaves a lot like Animation Graph’s transitions system, since my Blueprint Graph is telling the FSM Component to go to the Normal State as soon as the character ends his jump and on the other hand Normal State is being finished every 4 seconds with a link to Jump State again…
The result is a loop, my pawn is now jumping every 4 seconds by itself without any inputs from my Player Controller; with a Callback function which does nothing, I just put a Print String in that function for the sake of demonstration.
Instead of calling If (something) then SetState()… Just called “Finish State” function; And then the result is this, Normal → Jump → Normal —> rest 4 secs —> Jump… and so on:

You’ll still have to call “Finish State” function somewhere though; that is up to you decide when and where to call it, making the FSM Component trigger this automatic State transition only when you “approve” current State to leave.
After some more tweaks I’ll send this to Epic’s team for an update, hopefully it was very straightforward to understand what I was trying to explain :stuck_out_tongue:

Wooo this is great!, you are one of the most responsive developers here in the market. many thanks for this Bruno, this is looking excellent!

I have finished updating UFSM 1.4 for UE 4.15;
Gumroad pack is uploaded and ready, I have submitted Marketplace pack to Epic Marketplace Team.

Note: I am dropping updates for UE4.13 and lower as the core is no longer fully compatible.

1.4.0 for UE4.15 is now available on Marketplace.

Hello! Hola Bruno! I just wanted to ask a quick question that I;ve been searching for ages and I didn’t quite understand, but what are the posibilities of a FSM and, what are the advantages of using a FSM vs making all the controllers on the “pawn” for example? does it helps with multiplayer games where you can share a single FSM that can work with every character instead of hard copying all of the information from one character to another? or what other advantages it posses aside from making things cleaner?

E.

Yes you could share a FSM State through the PlayerState blueprint and have multiple pawns switch over to the same state, they would act like replicated behaviour for each different pawn across the network as long the blueprints use the same logic.
All would be needed is grabbing the uint8 State ID of the target pawn’s FSM… That would help you save a significant amount of data replicating throughout game’s internet connection as well.

You can use FSMs for absolutely anything you wish in your game design patterns, there’s some use case example videos on page 1 of this post.

{UFSM 1.5.0} : {UE4.15}

  • Implemented RPC Library.
  • Added GetCurrentStateName() function
  • GetStateID() function renamed to GetCurrentStateID()

In 1.5.0, I have added for you a Library of RPC functions that will help you out with networking,
multiplayer game development. Keep in mind these RPCs doesn’t implement multiplayer for you!
They are a package of functions which you can use to quickly manipulate FSM State from Clients
or Server with ease, but still do not enforce you to follow any particular networking model.
(you still code your networking structure your own way)

One thing you have to note though:

Internally, the ‘On Begin State’, ‘On Update State’ and ‘On Exit State’ events executes locally.
This is intentional, I do not want to risk throttling your game’s bandwidth; you replicate what
your game needs when you see fit for your particular networking model instead.
When you have to change and send a State from Server to Clients or from Client to Server,
the RPC Library have these built-in functions that will now help you out with these tasks.
The system will try to help you as much as it can; it will even warn you if you mistakenly call
a Client-to-Server RPC or Server-to-Client RPC in the wrong direction:

[CLIENT]: ‘Client-to-Server’ is called on Client FSM and executed on Server;
[SERVER]: ‘Server-to-Client’ is called on Server FSM and multicast execution over to Clients;

You get a little log warning if you, by accident, try to execute a multicast on Clients or try
to call a Client RPC on Server. Helps a little to keep sanity when making net code on Blueprints.
This will be specially useful for the people new to multiplayer networking.

Note this update is for UE4.15+ only, I basically re-wrote the whole thing and cannot keep it
backwards compatible after all the changes we had on UE4.15.

With this udate I will also make available the project demo converted to multiplayer logic;
There’s only three variable properties replicated for this entire Character Controller:

  • uint8 StateID
  • uint8 PreviousStateID
  • float StateTime

‘StateID’ replication is enough to let the Character replicate all of its behaviours across the
network, since all his actions are based on FSM containers, all one Player has to do is request
to the Server a StateID change, this simplifies multiplayer logic quite a lot and reduces
bandwidth traffic by avoiding replicating unnecessary amount of properties:


(I will send it over to Marketplace Team in few days, I suppose around two weeks you have it up)

{1.5.0}

I’ve finished revision for this update, demo project is now ready so I’ll submit the package with demo over to Marketplace team this next weekend.
Some of the last changes, added to the ones listed above, are:

  • Removed ‘Transient’ specifier as it is no longer needed in this case. You can fully instantiate FSM Assets now with no issues.

  • Added options for you to pick which internal properties you wish to replicate without having to dive into C++ code:

UFSMReplicateID.jpg

  • Successfully incorporated Unreal’s ‘Validation’ process exposed to your [CLIENT] Nodes.
    If, for any reason you see fit, the Client doesn’t pass a test and the validation fails then the Server will force quit the culprit Client:

2bc398fe9eb9b8a9c6320c4d53ff7ab35d7b15db.jpeg

  • I have moved logging from the Output Log panel over to the Blueprint’s Message panel.
    These logs will not fire if you uncheck the ‘Debug’ checkbox on your FSM Component;
    These logs fire only when you play in Editor and your FSM has checked the ‘Debug’ checkbox as well:

4e15a33527c2b2da857f953c0401698f3ea29aa3.jpeg

Hallo

I feel like I’m missing something but after installing this plugin the “Finite State Machine component” isn’t available to me in the add component menu.
All FSM nodes and the FSM project settings show up as expected.
Would be nice if you could tell me how to fix this.

Edit: I tried it in 4.14 and 4.15

Right click Asset Browser window and create your FSM Component Asset, from this menu:

After you create your Asset, your new FSM Blueprint will be visible in the “Add Component” list.

Great, Thank you!

This update mentioned above is now live on Marketplace; with changes included for the new ‘Include What You Use’ C++ specification.

Hello, new customer here. When I realized what this was and that you were focusing on multiplayer lately I couldn’t resist.

Where exactly do I find the demo project?

Hi, you can find RPC demo here:
https://www.dropbox.com/s/q3w0plo7w09j7qf/FSM_Demo_Multiplayer_UE4.15.zip?dl=0

  • Visual Studio is needed to build the Editor DLLs *

Thanks, got it working. Seemed like it failed to build at first and then it loaded up on the next try. Ouch on how easily those physics objects become out of sync. Have you been following this thread by chance?

Also wondering if 4.15’s new “Pose Snapshot” feature could assist in partially replicating rag dolls.

I know how to replicated physics, but I don’t see any benefits in doing it; it’s just a waste of bandwidth and will never work for people with bad internet connections.

{1.5.3}

I’m finally finished porting all latest additions, changes and bug fixes;
1.5.3 is already published for the Gumroad users, Marketplace version will take few days to update as usual:

  • Fixed a bug in AnimBP that is preventing Animation’s State Machines to propagate their States to the FSM Blueprint Component when OverrideFSM is checked, currently if you are not using 1.5.3 then your ‘UStateMachineABP’ is broken, please upgrade.
  • Ported all of latest features from UE4.15 over to UE4.14 and UE4.13 plugins.

Hi Bruno,

this is really really good and exactly what I was looking for. I hate messy code and blueprints get messy really quick. using your plugin made my life easier. one question though: i saw your wiki and you have a download link there. it is for free but you have a version on marketplace which costs money . are those the same ?

another question is: are you planning to implement automatic event creation for the states ? using a switch is really a bad practice as the states grow bigger and bigger. ( I am developing an rpg and the character has different animations for different weapon types)