Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

alt text alt text

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! :)

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);
     // THIS IS MY CODE!
     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 :P

Thanks a lot for your time.

Product Version: UE 4.13
anim graph.png (36.8 kB)
event graph.png (127.4 kB)
more ▼

asked Sep 25 '16 at 12:35 PM in Using UE4

avatar image

3 1 2 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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:

    1.you grab an arrow from the node (try Get Pawn Owner).

    2.place 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.


more ▼

answered Sep 25 '16 at 12:59 PM

avatar image

1.2k 33 25 66

avatar image Ansonix Sep 25 '16 at 03:02 PM

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.

alt text

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!! :D

avatar image mamoniem Sep 25 '16 at 03:43 PM

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:

alt text

avatar image Ansonix Sep 25 '16 at 05:42 PM

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 :)

Then I think everything is solved.

Thanks a lot for the help guys!!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question