Download

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?
ffaf6ececb7999fcd3a4a1e0a0070082bdc093f3.png
My key mappings
0d59e6a3ea8a86876d56cca432febfe4530202ef.png

By default I have [IDLE_WALK] state.
state_machine.PNG
The conditions for transition looks like this.
From idle to run
4bc886bcedcfef32d3b44f0c3b2a121a5254e377.png
From run to idle
48b2da0b5fa4e2202f67328993f7ee37dbb75e7d.png
Animation blueprint looks like this
7d72b111a419eb582a11cb33f4076c75202452ba.png

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

Hi
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
character_bp.PNG

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

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)
animation_bp.PNG.jpg

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.

BP1.PNG
b527b8b0159d17fb25d6a9623a25c7268d289d5d.jpeg

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.