Animation basics. Help me understand the UE Animation system

Hi all
I have a very limited prior knowledge of animations (ie. I understand how to create them in Maya, export to FBX, use Mixamo and in Unity some years ago I was able to create some fairly complicated character animation setups.

I’m using Unreal now of course, and just starting to look through documentation and tutorial projects. The one I’m looking at right now is the ‘Third Person’ example project built into Unreal. I am looking at the Mannequin>Third Person AnimBP:

Is all of this BP just there to set the “Speed” and “IsInAir” variables? And if so, could anyone point me towards the relevant part of the C++ API where these functions are found. It seems this BP is unnecessary to me (perhaps I am wrong, I am still learning).

EDIT: To be a little bit clearer. If for example I have an NPC character. And I just want him to have two animations (idle and waving). There should be an easy way in code to switch between the two animation states.

Your help here could save me weeks of messing around doing things the wrong way.

Thanks for reading :smiley:

You can’t change states from code.
Epic keeps the SetState() function private.

What you can do is create variables like ’ IsInAir ’ and change them from c++.
Then the state machine in animation should evaluate that variable and change state from there.

1 Like

Ok thank you for the insight. I thought I would be able to do that.
I now have a starting point will try to figure out all this blueprint stuff then.

I feel really dumb. But I have analysed this AnimBP (as pictured in question) for a while now, and in all three pages I don’t see any reference the specific Animation Sequences.

The entire thing seems to determine if the player is grounded, and then set the two variables.

Within ‘Details’ of the actual player blueprint instance in the level, I see it is set to “Use Anim blueprint” with that AnimBP attached.

But how is this doing all that magic making him fully animated for walking, idle, jumping etc.?

EDIT: Ooops! I found it. I had to click “AnimGraph” in the panel on the left.

Its a shame to be limited to this visual approach only but I think it will be nice once I get used to it.

The Character class is part of the Game Framework that Unreal has by default in the engine.

The character class will spawn an instance of that animation blueprint attached to the character instance and run the code in the animation thread.

They don’t allow you to manipulate states because animations run on their own thread.
Instead they give you an API to ‘query’ stuff from the outside from the AnimBP.
So a lot of people do this weird thing of checking booleans every tick.

I particularly don’t do that… I use UProperty reflection to set values directly into the AnimBP, but Epic don’t want you to do that.

1 Like

Create. Cpp animation class.
Instantiate it as a variable within the character.

Cast to it on begin play and on construction - do check that the skeletal mesh exists and the ABP is assigned.

This can crash out still if the ABP on the character doesn’t use the proper cpp class.
But generally speaking it allows you to push values to the ABP even from blueprint.

The alternative (crash proof) is to store the Animation Blueprint as a variable.
Since it’s a pointer.

Then in BP you can check that is valid and cast to the proper ABP on begin play. Save out the cast as a custom variable to push animation changes via BP.

One important thing that wasn’t mentioned here at all is fast path.

The way the default templates are setup basically prevents fastpath.

In fact they aren’t “examples” they are mostly a guide on “what not to do when using this engine, but we at epic do it anyway, cuz we so cool”.

In short.
You want 0 code executed on the animation blueprint.
Nothing at all. Not even an And statement apparently.

You make transition between states either happen with the Automatic checkmark - which is the only way to do animation time remaining in fast path.
Or a boolean which can have a !not as an exception to the And/Or rule.

Any Offsets or Bone manipulations etc. cannot have their Pins broken.
(breaking a pin simply means setting only what you need out of X/Y/Z, which anyone with a brain would think is Kosher and perhaps even faster, But apparently not.)
If you want to change the Z of a vector to move a bone up/down, you have to pass it a full on vector.
This affects how you need to create the CPP animation blueprint variables.
You can’t create and use a simple float because it’s all you need. You have to create a vector because that’s what Epic forces fastpath to use (for now? I’m hopeful they’ll eventually see the error of their ways in maybe 10 years when they go broke?).

So, to answer your initial question.
I’d your states are Idle and Wave, you need to first create a statemachine within the animation blueprint.
Then create the 2 states.
Then set a way for the transition between the 2 states to happen.

I’d you want this to happen from cpp code, you would then create a class for the character.
Change the character patented class to the one you created (make sure to derive it from character or you’ll get issues).
You then need to create an anim instance class. And change the animation blueprint class parenting.

With that done, you can initialize variables in CPP for the animation BP.
Make a bool, call it bWave. Set it to false in the creation (you don’t need to).
You may need to make it blueprint callable, so you got to look up the correct header you need for that.

In engine compile.
In the ABP you should now be able to pull a Get for the boolean to set your state transition up.

Once that’s done you need to get your character cpp to alter that variable directly where it’s at.

As such you need to get skeletal mesh, save it. Make sure it’s valid.
Get the mesh animation instance. Make sure it’s valid.
Cast to the animation class.
Make sure it’s a valid cast.
And finally, storing that value you can then ->bWave = true (or false) wherever you like.

2 hour setup the first time you do it. That’s for sure.

1 Like

awesome help thanks guys. I have managed to get some basic state machine up and running for a couple of my characters now.

My next big task that I remember struggling with , is targetting the animation IK for example to hold a gun correctly or to pick up a nearby object. Again I managed to implement this in Unity some time ago, but really looking forward to getting it to work on Unreal.

This is something I will have to do a lot more reading about, and then come back if I have any specific questions for more help.

Thanks again !

Check the content examples for hand IK stuff.
Also the new control rig - can SOME TIMES (read as almost never) be helpful with that.

1 Like