Call an imported animation through C++ ??

Forgive me if I am being stupid, but I am pulling my hair out trying to find a solution to do this.

So I have imported a custom model, then imported to start just 3 animations (well 2 if you dont include the T_Pose), So obviously I have set up the game so that when it begins the player is automatically in the idle animation, that works great! For simplicity sake the other anim imported is just a basic jumping animation which I would like to play up on “Jump” (spacebar) being pressed. Is there just not a simple function call you can do in C++ for this ??

In unity you can do this :

// Idle Method()
void Idle()
{
// Idle Animation
animation.CrossFade(“Idle”);
}

Is there no way to do similar with UE4! and if not how do I approach getting the animation to play via input ?? It just seems a bit silly to have an engine that powerful and no way to play an animation through code ??

Thanks in advance

GunnerJnr

I believe you use AnimMontages however there is not a lot of docs on how to call Animations through code, check this out:Playing anims from code? - Character & Animation - Epic Developer Community Forums

I wish there was an easier way through code but right now Blueprints is the way to go, however I would prefer to play animations through code.

Thanks a lot dude, I will look into this now, yea it just seems weird it doesnt just have a class you can do it straight from and call it directly, well maybe a suggestion on the UE Trello page ;). Thanks again.

Was just about to make this topic. Right now I can’t comprehend the usefulness of a blueprint state machine. There’s seriously no way to just type playanimation(“run”,etc,etc) like in every other engine I’ve used (even UDK had a way to do this)?

So you can set up montages to call from code but then how do you control their blending?

I haven’t looked into blueprint much but it seems like a PITA just to set up a few animations much less the hundred or so that I have.

Can’t you just add a slot node to the AnimGraph, then call:


float PlaySlotAnimation(UAnimSequenceBase* Asset, FName SlotNodeName, float BlendInTime, float BlendOutTime, float InPlayRate);

void StopSlotAnimation(float InBlendOutTime);

bool IsPlayingSlotAnimation(UAnimSequenceBase* Asset, FName SlotNodeName );

I haven’t tried it, but that would have been my first try when needing to trigger an animation from code.
Then again, I’d probably be triggering single anims, I’m not sure how friendly it’d be with looping.