Setting up a Key Event

Hey, I’m trying to set an animation state variable in an anim BP so that a character switches animation based on my custom variables; I’m trying right now to bind the state switches to keys for testing purposes. What’s the simplest method for achieving this? I currently have a ‘Chase’ State linked to a cone-of-sight calculation and it works, so all I need to do is bind these variables to keys. Thanks in advance!

In your actor you’ll have key events. Those events will set variables. Your actor will reference your animation blueprint. Your animation blueprint will obtain the actor by using “Get Owning Pawn” or “Get Owning Actor”. You’ll then cast that to your actor class that is setting the variables on input events. You can drag off from the result and get the variables you want then set your animation blueprints variables to the values you got from your actor.

Good luck!

This is what I have so far:

Currently this does not work (I am setting up the key events in my FirstPersonChar. and the AnimBP references an NPC who’s animations I am controlling). If, in my FPC blueprint I do not include the Cast, the BP runs and the key press is recognised, though nothing changes in the NPC’s animations.

I see. What you need to do, is reference the NPC in your character blueprint somehow, “Get All Actors Of Type” or a collision check. Once your FPC blueprint has the NPC reference available you’ll cast that ref to your NPC class and set variables on the NPC from your input events on FPC.

Open up your NPC and select the skeletal mesh component, use the animation blueprint of your choice. Then inside the animBP your “Update Animation” event should be setting it’s variables from the NPC values.

That should work.

Okay I’ll give this a go thanks :slight_smile: