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!
asked Jul 23 '14 at 12:28 AM in Blueprint Scripting
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.
answered Jul 28 '15 at 04:24 AM
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.
answered Oct 08 '14 at 11:57 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here