How to affect an animation's rate scale in C++?

Hello I would like to affect a gun’s firing animation rate scale in C++. I don’t want to have to create an Anim graph for one animation nor do I want to use Blueprint in this instance. Is there a way of doing so?

Hi, you could use the function Montage_SetPlayRate():

I hope this helps, and good luck.

Wait I am not using a montage I am just using 1 animation instance.

This function is called on an Anim Instance object.

Edit: You are right, it requires a montage parameter. Apologies. Perhaps you need to create a montage with the gun firing animation in order to adjust the playrate.

I am using an animation asset object. I am sorry for being misleading my mistake.

When you say Animation Asset object, do you mean an Animation Sequence? If so:

https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/Animation/UAnimSequence/

There is the parameter RateScale in the AnimSequenceBase class:

/** Number for tweaking playback rate of this animation globally. */
UPROPERTY(EditAnywhere, Category=Animation)
float RateScale;

So then just create a montage with the UAnimationAsset that I am using in .h then play the animation via the montage in c++.

I mean a class UAnimationAsset*.

From what I can tell, UAnimationAsset is a very generic class that allows you to put any type of animation asset into it. Can you please send an image of the animation asset you are plugging into this parameter? I suspect its an Animation Sequence, but I want to be sure.

It is an animation sequence I checked.

If it is an animation sequence, then I recommend you change the parameter in C++ from Animation Asset to AnimSequence. That way you will have access to the RateScale parameter I mentioned earlier and that should do the trick.

//Declaration
UPROPERTY(EditAnywhere,BlueprintReadWrite,Category=“UAnimationSequences”)
class UAnimSequence* FireAnimation;
//.cpp
//Rate scale modification.
FireAnimation->RateScale = 10.0f //or whatever.

Thank you very much for your help! You guided me in the right direction. I really do appreciate that Devin.

That makes things much easier wow!