Download

How can I programmatically select what animation plays in a certain state?

I’m making a game that has 30 different types of attack animations and 10 different types of emote animations.

I want to be able to construct a state machine that basically transitions from:

  • Idle to/from MeleeAttack (Has 10 different animations)
  • Idle to/from MagicAttack (Has 10 different animations)
  • Idle to/from RangeAttack (Has 10 different animations)
  • Idle to/from Run
  • Idle to/from Emote (Has 10 different animations)

Is it possible to programmatically tell the MeleeAttack, MagicAttack, RangeAttack, and Emote states what Animation to run at runtime (either through Blueprint or C++).

I can’t seem to find any guides that do this, they are all preconfigured 1:1 animations to states.

I hope this helps.

Thanks, I’ve looked at that article before. However, it only defines 1:1 states.

I’m looking for a way to do something along the lines of:

SetAnimationStateAnimation(MeleeState, MeleeAttack1AnimationAssetRef);

Where “SetAnimationStateAnimation” just swaps out the animation currently being used for the MeleeState… Is this possible, or do I have to bake all 40 animations into the state machine…?

Thanks again, but I took a look into montages and… to my understanding… they are just used to combine animations into a new animation.

I think I’m getting closer to what I want… In this picture my Melee State allows you to pick what Animation Sequence is being played. However, I have no idea how to programmatically feed in that Sequence value… Is it as simple as creating a Blueprintcallable C++ function in my Character class that returns the asset sequence ref? I’m about to try that now.
https://puu.sh/Hz8Ao/34e888ab57.png

I tried what I said but it does not work (no animation plays).

My C++ code for the GetAnimationSequence is:

UAnimSequenceBase* AHeroC::GetAnimationSequence()
{
    UAnimSequenceBase* AnimationAsset = nullptr;
    FStringAssetReference assetRef("/Game/Character/Animation/MeleeAttack2");
    AnimationAsset = Cast<UAnimSequenceBase>(assetRef.TryLoad());
    return AnimationAsset;
}

You missunderstand the montages.

You set up the montages and you que/play them from blueprint however you see fit.
Thats your “programmatically”.