Logic Driver - Easily Design Gameplay Systems with State Machines

Yep, you’re right that the initial tick calls OnStateBegin and the second tick evaluates transitions. I can also see how you might want that done on a single tick so I just added in an option for all base state nodes to support that. I think defaulting that setting on Conduits to true may make sense as well.

I’m happy with how this is testing so far and will include it in the 1.6 update. I don’t want to road block you and can provide you a beta build sooner if you would like.

That’s great. I’m fine waiting for 1.6 :slight_smile:
Thanks.

I love this plugin. Its made my life easier.

Coincidentally, I’m in the same boat as the post above, I need conduit nodes to be able to evaluate transitions out immediately on same frame.
Figured I would post support for the plugin and queue up my request for the same feature on UE 4.23.
Looking forward to 1.6. Thanks!

1.6 update is just about wrapped up for 4.22-4.24 and I’ll be submitting to Epic soon. With the holidays and their delay from 4.24 processing I wouldn’t be surprised if it’s not available until after Jan 6th.
I updated documentation here Private Repository Access & Custom Builds · Recursoft/LogicDriver-Example Wiki · GitHub if anyone wants to try it earlier. I’ll be busy myself over the next couple days as well but should be able to provide a build earlier than the 6th if needed.

Every state node will have an advanced check box to enable same tick processing. Each transition node will also have a way of opting out in case you need some transitions to eval right away or others on the next tick. This is mainly to prevent blocking infinite loops (self transitions default to opt out to help prevent that). Conduit default behavior probably won’t change so as not to negatively effect existing logic.

Awesome! I’m looking forward to it!

I have 2 feature requests. v1.7 perhaps?

The first is regarding inheriting state machines, ex: B inherits from A.
To access the A state Machine from B, I am adding a reference to A inside B. This is based on advice given above. This seems to work and allows me to extend it because the context is passed in automatically and I’m only ever referencing the character directly for variables checked etc. However, I suspect it’s not a good way to proceed since if I add variables to the base (A) state machine, I can see and use them in all of the children (B, C, D, etc), but they are not accessible to the referenced instance (A) since its a reference to it’s own separate external instance instead of the parent itself…
Reading the wiki this morning, I guess I can use an intermediate graph to forward my variables to the reference… but this all has a code smell as they say. Variables defined in A are forwarded back to a reference of A from B… yeah. Just the way the code folded in the end, nothing done wrong here. This would be flawless if not for my desire to share inherited variables.

Is it possible to maybe add a node for getting the parent graph? It would be nice to treat the parent like a nested state machine so we can just transition in and out of it…
A could contain states like travel, jump, dash, etc which are shared with many characters. B would contain melee states unique to each character . Both can make use of the same global variables defined in A and it’s handy to use A as a base class in each character. but again, I’m working around this by keeping variables in the character, which is ok so long as I don’t forget they are used only in the state machine when i check reference on them in 6 weeks during code cleanup.
I imagine maybe only 1 instance of “parent State Machine” node should be allowed? Food for thought.

The second request is to do with the actor component. maybe I missed it, but is there a way to construct a new one from blueprints to assign it a new state machine class reference?
If I wanted characters to “change powers” and each power would be its own state machine (which inherits from the basics of A above :wink: , I didn’t see a way to do that. I’ve worked around this easily because using variables is so easy (thanks to the clean workflow!) but I think a function to maybe “reset” the actor component and giving it a new class reference as part of it might help recycling the actor component.

Neither of these are critical features. Nice to haves to minimize workflow overhead at best.
I’m happy to test out and provide feedback if you like. I’ll send you an email with my receipt as requested in the link. No rush if you are out for the holidays.

Happy Holidays!

Update 1.6
Supports Unreal Engine 4.22 - 4.24

Full Patch Notes
This version has changes which may impact current users, please read the patch notes.
Potential impacted use cases:
Referencing the same state machine class multiple times in a single blueprint.
Reloading states by Guid during run-time.

New Features:

  • Reference Templates (archetypes) are now supported
  • New Parent State Machine Node Available in Child State Machines
  • Optional Same Tick Processing on all State Nodes (Including Conduits)

If a client drives the transition, is there server side anti cheat logic too? Like I could have a client side transition to fire a weapon, but I’d want the server to validate that the weapon is fireable as well.

It could be good for optimistic logic where the client tries to start the state locally and all the animations play so it feels immediate. Then if the server responds with a “No” there could be a way to undo the client transition.

Not currently, but I agree with you. Allowing the server to evaluate the same transition the client sent and forcing the client back into a previous state if the transition fails makes sense. So does an option for taking the transition optimistically. I’ll add this to the backlog.

Is there a way to get references to transitions and states in the blueprint?

I saw some blueprint nodes that reference things by guid, but I’m not sure how to get a guid either. I’m wondering if there’s something like get guid for transition “Equip to Idle” and set “Can Evaluate” to true when my character’s weapon equip animation is done. I see there’s a way to get a reference to only the “Current” state or transition if you use “Get State”.

What I’m really trying to do is trigger a transition manually after some time in On State Begin, like when my character’s animation is done. Before using this, I had code that manually said, After Timer, Go to state X. I saw there’s a function for If X time spent in state, but I wanted to avoid having to know that data in multiple locations. I thought it would be nice to use a Delay node and trigger it from one place in On Begin.

In blueprints there isn’t a way to get a true reference to a node. The GetStateInfo and GetTransitionInfo provide read only information. This is for a couple reasons: one is technical - how the nodes end up getting compiled into the blueprint makes it difficult to pass references throughout the blueprint, and the other is there really isn’t a reason too. If you find yourself needing to manually change a value on a node there’s *probably *a better way to do it.

For your case I’d consider going about it one of the following ways:

  • You mentioned Time in State - That works in transitions as well and in that case it’s actually reading the time from the previous state.
  • Depending what the context is (such as if it’s the character in question) you could set a property on there to complete when the animation is finished and transition when that is true. Or add a way to read the max time of the animation and then do Time in State >= Context.EquipTime.
  • You could also take an event based approach: In the transition bind to an event that fires when the animation finishes and set Can Evaluate there. Transitions · Recursoft/LogicDriver-Example Wiki · GitHub has an example of that.

It’s worth mentioning that one of the next planned features will be reusable node classes. With those it would be possible to get references to their instances as well as set common logic that might be shared across multiple nodes.

Oh yeah I’m definitely looking forward to the reusable node classes. I had a similar state machine system a while ago where I just had state classes like in the Unreal Tournament 4 code and having local variables and functions was nice. You can reuse a class for all Shoot weapon states, for example. Do you know when that will be/how hard it is?

One thing I was considering at first is that for every state I have a boolean in the state machine that gets set to “Done” and the transition waits for the property to be true, but I was hoping to avoid that since the State Machine will be bloated with all these properties.

The event thing you mentioned could work for now until the reusable node classes. It will be similar to the approach of having a boolean but the class itself won’t be bloated with a bunch of bool variables. It’ll instead be bloated with events, but those don’t get in the way of the code. They just “exist” in the class.

I also used Gameplay Abilities at one point for weapons because they do networking but it became a nightmare to work with for states so I’m switching to your FSM plugin. In Gameplay Abilities, you can have an ability say it’s Ended. I’m not sure if it makes sense to tell a state, it “Ended” and let the transition go. I think in the end, having State Subclasses will make sense since a state can set some property on itself and the transitions out of it can trigger.

It could also be good to manually trigger transitions out of a state immediately with a blueprint node. There might otherwise be a delay of a game tick. Normally in code I’d say, “Go to state X” which ends up behaving like a State Machine you set up without your UI based plugin. It could be nice to set up transitions with your plugin and have a state know which transitions go out of it. And then have some code within the state manually invoke the transitions that come out of it.

Custom class development started about a week ago and the bulk of it is already working. You’ll be able to extend classes either through C++ or BP, then select the class from a state machine BP.

It still needs some more work and a lot of testing and is also part of a larger update so I don’t want to give an ETA. But when it’s ready for beta if you’d like to test it I’d love the feedback. Check out this page if you’re interested.

Another thing with this update that may help your use case is I’m planning on making the state class instance available in the outgoing transitions. That way you can just check the state member variable to see if the transition is allowed.

Sounds great!

@Recursoft Just stumbled onto this - looks awesome and perfect for some stuff I am working on.

Question about performance and scalability: Is the state machine evaluated in the Blueprint VM on the main thread or is it compiled ahead of time? I want to use it for a large number of entities ( like 500+ )…

Thanks for any feedback

Wow that’s a lot of state machines!

Any logic you have in any state or transition graph is going to be evaluated through the Blueprint VM on the main thread. Most VM overhead would come from evaluating transitions each tick which is the default behavior. It’s possible to bind to events in the transition graph and disable evaluation until the event is triggered. Transitions · Recursoft/LogicDriver-Example Wiki · GitHub has an example. The SetCanEvaluate call physically prevents the Blueprint graph from being evaluated.

You can also change the update rate of the state machine and Blueprint nativization is supported as well (as long as the blueprint logic you use also supports it).

Hope this helps! Let me know if you have any other questions.

How possible would it be to dynamically change State Machine references on the fly?

Say I have some common super State Machine A and inside is a state Machine Reference Node. It would be nice to reuse State Machine A and tell it to change the reference node to some arbitrary Reference. Right now it’s only possible by duplicating State Machine A.

Right now it seems like parent state machines can only be sub state machines but there’s no way to create reusable super structures of state machines with child sub state machines.

You’re correct that adding a reference can’t have its class changed during run-time. That information is used at various points in compile time including knowing what variables to read or write to the reference in case of the intermediate graph and what template to use. The reference is then instantiated once during initialization and internal states mapped out for use within the top level state machine.

Implementing dynamic reference classes during run-time isn’t trivial, but I’ll add a note to the backlog to review everything it would take to add that in. The backlogs adding up!

To do something like you want now you could create a state machine variable within a state machine and use a state to initialize it.

Pass in whichever class you want.

Then in the transition leading out do something like this.

If you go this route you might want to do some validation checks on the variable and also call shutdown on the state machine if it already exists.

To add: This may not work well with replication. You might also want to disable the tick and then call update manually from within the state.

Here’s a preview of upcoming features:
Version 2.0 Feature List

https://i.imgur.com/sXwkECJ.png

The update is currently in private beta testing. Special thanks to @xdbxdbx for a lot of great feedback!

If anyone would like to beta test the update, please follow the instructions here. You’ll need to be comfortable compiling a plugin from source.

Hey, wanted to share a couple screenshots of the upcoming 2.0 update.

A Logic Driver powered cutscene test from @xdbxdbx

A WIP puzzle for my game.

Thank you to everyone who’s been beta testing it!

Awesome plugin! I had used it in my game. It works like a charm, and the support of cutscene in 2.0 is truly amazing. And will we be able to create state machines using C++ in 2.0? Although the performance and efficiency of blueprints seem to be great enough for me currently, but I would certainly love to be able to create them using C++ like other competitors (e.g. UFSM).

BTW, it might be a bit minor, but I would prefer to see a new icon in 2.0 as the current one is slightly a bit old school (XP styled) perhaps?