Calling function in state machine transition rule?

I am creating a fighting game, and I want to check inputs in my animation state machine’s transition rules to figure out whether I should execute new moves. The player’s inputs are stored in a buffer in a character blueprint, and I made a blueprint interface function that checks whether the player’s current inputs match a given input sequence. I added that function to the state machine transition rule, but the problem is I can’t find anything to hook up the exec pin of my function, so that function never actually executes during gameplay.

Below is an example of what I mean. Is there something that I can hook up to the exec pin? Or if this requires C++ code, I’d be happy to look at that as well.

As a side note, I know I can execute the function in the Event Graph of the animation blueprint, but it seems more convoluted, at least to my understanding. If I wanted to add a new move that starts from the “Idle” state, I’d need to 1) keep track of a “state” variable, 2) check the input in the event graph when state = Idle, and 3) add the animation for my move in the anim graph. Using my current approach, if I can get this function to work then I can do everything in the anim graph…

Of course, if what I’m trying to do isn’t the optimal way of doing things, I’d love to hear from someone more experienced. Thanks!

You need to go to the state machine graph and select your transition. Then on the properties tab you will find a notifications section where you can define an event to be fired before or after the transition. Then on the transition page you will be able to add the created event and wire it to the “Input Matches” node or whatever you need.

1 Like

Can someone show me a screenshot? I am not able to follow. I aded “Custom Blueprint Event” that I have created in the event graph in Notifications–>Start Transition Event text box. The event is not being called.!

Can someone show me a screenshot? I am not able to follow. I aded “Custom Blueprint Event” that I have created in the event graph in Notifications–>Start Transition Event text box. The event is not being called.!

Similar issue, I have added a custom event in the Notifications–>Start Transition Event text box. But when I right click inside a transition graph, the option to add the event doesn’t show up…

You should make your InputMatches function a “pure” function. A pure function is a function that promises not to change anything in the object it operates on, which means it only retrieves data. Pure functions do not have execution pins, and thus are called automatically when then input is requested, thus in this case it will automatically call the function when the state machine checks the transition, as long as you hook up the output bool of your function to the “Can enter transition” bool. An example of a pure function is Actor’s “GetVelocity” function; you’ll notice it doesn’t have an execution pin.

To make your function pure go to where you have it defined, which it sounds like is your character blueprint, then select the function from the functions list in the My Blueprint tab. When the function is selected you should see some options on the right in the Details panel, including stuff like description, inputs, outputs, etc. In the Details panel you should see a “Pure” checkbox. Click that box, recompile your character blueprint, then call the function from the transition rule and pass its “Match” output bool into the transition rule’s “Can enter transition” pin.

1 Like

Perfect! This removes the white execution arrow and solves the issue.

Thanks Gatherer. Although you made a small mistake. You will not find your defined event on the transition page but on the event graph.

Thank you, Gatherer! Super helpful. I’ve been searching for how to just fire off some event from a state machine.