UFSM: Finite State Machine

Hmm… I see in your screenshots that you have attached a “raw” FSM Component to your BP_Pawn asset.

“+Functions” ( function generator ) only works when you create a Blueprint asset for your FSM Component… (right click Asset Browser –> Synaptech menu –> New FSM Component).
And then within the new FSM Blueprint created you can generate functions.
​​​​​
If you try to generate functions from your class instead of a Blueprint of type FSM, Unreal ignores you because it knows the Code Reflection system won’t work in that case.

If you don’t want to create a FSM Component Blueprint then you have to create all your functions by hand… It’s the way Code Reflection works.

TLDR:
Attached “raw” FSM Components and FSM Blueprints are different things.
You can create a FSM Blueprint and still attach it like a normal “raw” Component, so is always better to create a FSM Blueprint asset unless you don’t use “Auto-Flow” or go full C++.

Awesome, I didn’t see that in the wiki article. I’ll try it and let you know. Thanks :slight_smile:

Thank you for the fast replies.

Well that seems to have cleared up not being able to generate functions. However my enumeration still seems really messed up. Here is a screenshot showing the enum should be on the state “AcceptInitialBets” but in game, the FSM debug is reporting the state to be “Attract_DealCards”.

This is my fault btw…
I have to learn how to create better documentation. Things seems obvious to me then I don’t remember to mention them when writing how-to guides.

It’s no problem; I’m used to dealing with a lack of documentation. Definitely helps that you respond so quickly :slight_smile:

I guess the root of my issues is this node fsm_states_enum.jpg

Like I was saying, it seems that the state enum being output by any of the fsm component events (onUpdateState, ect) is different than the enumerator that I have created and named Enum_States.

Are you using “Set State…” nodes anywhere?

When using FSM Animation BP (which is optional btw), on the Pawn/etc you should never use Set State nodes then.
The Anim BP will always try to control by itself the State your FSM Component is at, so you have to make sure the Target FSM name in your Anim BP is exactly the name of your FSM Component attached to Pawn.
States out of sync in that case seems to be due to the Anim BP not able to find the FSM Component at all.
​​​​​​
Also, reparenting your Anim BP isn’t a requirement anymore. There are new animation nodes (red events) that can be used in any AnimBP Graph now.

hmmm, no set state nodes anywhere. I’m currently moving my code from being all in the game mode (and being dependent on that enum) to their respective functions in my newly created bp_fsm_component.

I would be willing to share more of my project/issues in a more private context as this project/game is going to be released, ect ect. (if you want to know more of the issues I’ve faced/want some feedback on what could be added to the wiki article to help future users out)

The “red event” node I was referring to is a new node you can use from any Animation Blueprint Class.
Did you try to use this one?
It’s what we use on our projects instead of re-parenting AnimBPs (to sync FSM States to Animation States):

is that needed if I am using OverrideFSM True?

I tried using set state and it doesn’t seem to change anything. I refer back to one of the images I posted previously, this is still happening,


basically, the anim graph is correct and the state should be on acceptinitialbets, however, the debug (and a printstring attached to the update function for attract_dealcards) confirm that the state machine is running and talking to blueprint correctly, but the state that is being output as the active state is somehow different/detatched from my enumerator. (and now also from the state which the anim bp is in)

No, that is an alternative system.
If there’s a bug hidden in the system you are currently using, maybe this alternate system works the correct way on your project.

I was rebuilding the Blueprints I use for development (for tests) in the Demo Project while we speak and unfortunately I cannot reproduce the “out of sync” problem you experience…
I would have to have access to a project where I can see the problem you have for me to understand what is going on there.
I’ve never seen it so far, just remade test Blueprints to see if the problem is new on UE4.19, but nope; working correctly here:

If you can make a small barebones project to show me the problem I can than take a closer look.
Usually this kind of thing happens when something was setup wrong (happens often with the Object Pool for example).

The step I found confusing is in the fsm_component, when we set the enumerator, what enumerator should this be? fsm_component_enum_variable_Space.jpg

Are we supposed to just make a new enumerator and list out the states, what order should those states be in when creating this new enumerator? This is where I think I messed up and ordered my states incorrectly while making a new enumerator. I was very careful to make sure the names in the enumerator were the same as the states that are in my anim_bp’s FSM.

ok only double posting because I think I have some easy steps for reproduction of my issue. If you set up your enumerator first, and then change the entry point on the anim fsm graph, it becomes improperly ordered/detatched from the enumerator.

I guess I should change source for Animation BP to set FSM States by Name instead of ID.
​​​​​​That would avoid the problem you have; I use ID because it’s faster to tell the Anim BP to use IDs instead of FNames…
I will look into this when I go home.

Btw, when using FSM Anim BP’s to sync FSM Components, the enum workflow is irrelevant because the FSM will erase all the States you’ve created from that Enum then it will copy the States you have in State Machine of AnimBP.
This is what the “Override FSM” checkbox does.

So in that case the Enum is only useful to generate functions in FSM Blueprint.

Still, just guessing, since I don’t really know what is going on in your project.
I would uncheck the “Override FSM” option and sync with red node posted above, because if I remember right that sync States by Name instead of ID.

I’ve changed FSM Anim BP to sync FSM Component’s States by FName instead of by ID.
Literally just had to change 1 function call, that might solve the problem in your project…

If I understand right what is going there, then this will resolve the problem.
When going home I’ll PM you about it to show the fix.

Thank you for the info regarding how the fsm interacts with the enum. :slight_smile:

I think I have it working as desired for now (although that doesn’t mean there isn’t room for improvement :wink: )

I’m having an issue with state changes. The state machine isn’t changing to the state requested. Instead once a state change is requested it’s going to the next state in the enum.

OnBeginState is receiving the ID for “charge” but also the name “attack”.

So set-by-name is evaluating wrongly and the name passed through isn’t validated against what state is chosen in any case.

Have I misconfigured something somewhere?

Also, I’m not the best C++ dev but is it possible that you could use C++ templates to get away from the raw byte IDs and names and use the actual enum in many places?

The Ids in Enums aren’t necessarily the Ids generated into the state machine.
This is why you get wrong value when comparing to source enum.
All the Enum does is feed generated States with their item names.

​​​​​As you can see, in the “FSM States” list the Id of “Attack” is 2.
This is why you get the output of index 2 from your “AIState”, in the case above: “charge”.

The indexes in FSM States list doesn’t match your enum.
You can set Enum to (none) then set the enum again to regenerate “FSM States” list; most likely you’ve changed the enum and didn’t update the FSM States list afterwards.

I will see if I can change nodes to use Enum instead of typing names without breaking networking;
But that is a big refactoring and I don’t know yet if it’s a good idea.

Gotcha, cheers!

I did reset the enum in the state several times in that way but it didn’t fix the issue. I’ll switch to using names instead though.

If using a C++ template works (and I’m not sure it will with custom user blueprint data types made in the editor) then it’s a very minor syntax change. But a better plan might be to make the ID try to be consistent with the enum byte ID as that’s what most people would expect. Alternately ditch the ID as it’s not set explicitly and it can change without the developer realising, force everyone to use the name instead.

Dynamic enums for Blueprint users would require custom K2_ nodes.

If I make these nodes then plugin source code will expand in a magnitude of thousands of extra lines :slight_smile:
I’m still pending writing docs for an unrelated update (Savior 2 update), but as soon I finish documentation for that system I will work on this.

Edit:
I will absolutely work on more User Editor features, being not satisfied with this workflow based on “Details Panels” myself as well.
I just couldn’t properly afford the time to create a “real editor”, had to deliver things faster, but this is still in my to do list since the beginning and some day it has to materialize ^^

Hey. I want to try to use UFSM with this PaperZD plugin for my 2d project PaperZD in Code Plugins - UE Marketplace
I haven’t purchased it yet but I think it won’t work correctly because it is using it’s own anim bp class. So the question is, is there any possible workarounds for using UFSM with custom plugins such as PaperZD? Any ideas?
Thanks!