Change animation blueprint variable


I am very new using UE4 (my first week learning). I am very confused between what goes to C++ and to the Blueprint editor and how are related between each two.

So, I have started a c++ top down project. I have setup a character “behaviour” from idle → walking → to running through blueprint event and animation graph.


So I have basically 2 variables, which are speed and isAttacking.

The speed works more o less good, since is the tutorial I find everywhere, but I did instead of a blended animation, just as separated animations to see if I managed although for what I read is not the best way (learning purposes!). Sometimes the animation gets stuck in the run, but if i debug the graph works good the graph, so I hope is only a visual thing of the editor, but thing for another moment! :slight_smile:

Also in the c++ part is done by default when you create the project.

So then I have mapped in the settings/input, that when you press A key, you “should attack”. The idea is to move from idle to attacking state when “isAttacking is true”, and go back when the attacking animation is almost finished.

I have created the following code in the c++ part:

void ArpgPlayerController::SetupInputComponent()
	// set up gameplay key bindings

	InputComponent->BindAction("ResetVR", IE_Pressed, this, &ArpgPlayerController::OnResetVR);

	InputComponent->BindAction("Attack", IE_Pressed, this, &ArpgPlayerController::OnAttack);

void ArpgPlayerController::OnAttack()
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "HELLO!");

So I have setup the OnAttack function, that is bound to the “Attack” input key “A”.

But in here I am totally stuck. If I press A, certainly appears hello on the screen, but I don’t know if in here I should set the variable “isAttacking” to true (and if so, i don’t know how to access to it), and when the key A is released then set to false. Or I am doing to much and it’s not necessary to do this like that because maybe I can do from the editor directly…

Also I don’t have very clear where is the line between to add stuff in c++ and into blueprints (or if I can combine them, like trivial easy things in blueprints and more complex things in c++), and neither in how they are connected (c++ with the blueprint editor). I think this is the part that I’m the most confused right now.

I hope I could post clear, since I am also learning the terminology and probably I name things wrong :stuck_out_tongue:

Thanks a lot for your time.

Defaiantly you need to set “isAttacking” to true while attacking and then reset it to false by the end of the animation. ABout the how to do it, so let me ask you first where is the “isAttacking” variable is?

  • If it is in the animation blueprint, so you can get the current animation blueprint and set the value using this way:
  • The other way, which i mostly recommend, is to have the variable within the character class (blueprint) and another variable with the same name and type within the animation blueprint. And you always set the variable value (within the animation blueprint) to match the one from the character class, always in the update (Event Blueprint Update Animation). And if you asking how to do it, so in ur second screenshot: grab an arrow from the node (try Get Pawn Owner). a node named "Cast To XXXXX) where XXXX is your character class name.

    3.Then you get the variable value from that character class been casted, and use its value to set the local variable.

If not clear, let me know.


Hi, thanks a lot! You gave me a new path to go!! So I have followed the second option, the one that you recommended me and finally I have found in the character class (blueprint) there was a little link in the top right to extend the view so I could also see in there the graphs.

In there I could create the event when the attack is performed, and set a variable in there. Later on, in the animation blueprint graph I could set it as is shown in the picture.

However I have a last problem, that is that the attacking only works if previously I had passed through the speed node. Which it seems true because is the set of speed link that goes to the cast node. I see it was not possible to have two links from is valid, one to the speed (as it was) and another to the cast to topdownCharacter.

Is there a way that I can have the set speed and the set is attacking in parallel? So I don’t depend to first move to attack, and neither to first attack to be able to move (I mean play animations).

Thanks a lot for your time!! I am almost there!! :smiley:

Use the Sequence node after Is Valid: Flow Control | Unreal Engine Documentation

dude, the “IsValid” will always execute what you have above, as long as the character is exist and it has animation blueprint attached.

At your character blueprint, did you select the “Skeletal Mesh” and set it’s animation to “AnimBlueprint” and choose your animation blueprint?
I’m asking because this is the only thing that could make the “isValid” return false.

A good way to test if the code get executed and the problem is somewhere else (which I suspect), is to add a print message after the “Set isAttacking node” to print anything, and then go and play, and see if there is things printed or no.

  • If things not printed, so it might means the AnimBlueprint is not been detected.
  • If it is printing results, then it means the issue might be in those arrows:

Lol, I feel embarrassed. The sequence node works good, and I can play both animations. I actually was stuck that the attack was not playing if I was not moving first. Not true. It was because when I push the play button in the editor I hadn’t the focus on the screen so it didn’t react to any key, and only when I get the focus of the window clicking it (click means also that the character moves) then it reacts to it. So basically now if i get the focus of the window without moving the character it attacks when I play A.

OMG, well that was funny and lame at the same time hehehe :slight_smile:

Then I think everything is solved.

Thanks a lot for the help guys!!