set variable when some key is pressed

Hi there!

I am trying to make an ability for character to run if the key [SHIFT] is pressed.
But how to do that in the character blueprint?
My key mappings

By default I have [IDLE_WALK] state.
The conditions for transition looks like this.
From idle to run
From run to idle
Animation blueprint looks like this

How to access the variable Is Shift Clicked that supposed to make a transition to my [RUN] state there?

2. Drag wire from “try get pawn owner” and cast it to your character.
From cast node “as…” drag wire and type “get sprint”
Set with that variable sprint in your anim bp

  1. In your char bp, create variable bool sprint,
    On sprint pressed, set bool to true, on released set it to false

I created variable

However I have no action for get sprint in my animation blueprint

Yes, because you not dragging it from “As Character” pin as i said :slight_smile:
Btw i think that cast is bad anyway, you must cast it to Your created character, for example “skeleton_character” or “my_sprinter” or “thirdPersonCharacter” if you using that template… just class which you created or where you are setting sprint… so replace cast node and drag wire from “as …” and everything should work

Did you mean like this? (though not exec line connected to set speed now)

Because I am not sure whether I can access character variable inside state machine.

Here’s how I’d recommend setting it up. I have a setup for sprint in a game I’m working on.

I don’t set a boolean value when I sprint. I alter the Character Movement value ‘Max Walk Speed.’ This dictates how fast your character goes when you’re providing movement input.

As for the animation graph, I’d recommend just using the value Speed you already have in your animation blueprint and using that as an input to a one dimensional blendspace that has speed as its variable.

Also, if you wish to access booleans in your animation blueprint, make sure to uncheck ‘Context Sensitive.’ It will disallow you from seeing that variable since it was created outside of the anim BP. I provided a screenshot that accesses my two variables I created for run and walk speed, and access of the boolean will be identical.


just connect sprint-> with ->speed with white execution line, if you get errors click on them and show me node where it writing error

Fair enough. As I have to set max walk speed after key pressed or released anyway. I am too new to BP to do refactoring already :slight_smile:

You mean set sprint exec with set speed exec? Ok. I get it.