Movement and playing animation

Hey, why you make your life so hard with this code? :slight_smile:

Use Animation blueprint, this is exactly why epic did Animation Blueprint!
Animation blueprint is a state machine animation system which works with different states and you dont need handle blends or anything else between animations, you need only do the logic what and where can blend!!!

From other side, your code is totally wrong… because you looped the animations and play simple anim asset should be not override each others…

If you really wanna handle animation playing from code instead of Animation Blueprint (REALLY REALLY NOT SUGGESTED)
you should play anim montages instead of anim assets…

you can read about animmontage here: Animation Montage | Unreal Engine Documentation

hope this helps. cheers

Hello. I am working at movement animations. I have Bind Axis (which means the function is called in every frame). If Value = 0 then there is no movement, if 1 or -1 then character is moving. But the animations are played non-stop.

I need check what animation is already playing or something like this, but idk how. Now the animations is overlap and this is not working correctly.

UCharacterMovementComponent* CharacterMovement = GetCharacterMovement();

CharacterMovement IsWalking() is always true…

I will be grateful for your help

void ASieCharacter::MoveForward(float Value)
{
	if ((Controller != NULL) && (Value != 0.0f))
	{
		// find out which way is forward
		const FRotator Rotation = Controller->GetControlRotation();
		const FRotator YawRotation(0, Rotation.Yaw, 0);

		// get forward vector
		const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
		AddMovementInput(Direction, Value);
	}

	if (Value == 0.0f)
	{
		FName anis("/Game/LowPolySkeleton/Skeleton_Mage/Anims/mage_idle_1.mage_idle_1");
		UAnimationAsset*animIns = Cast<UAnimationAsset>(StaticLoadObject(UAnimationAsset::StaticClass(), NULL, *anis.ToString()));

		this->GetMesh()->PlayAnimation(animIns, true);
	}
	else {
		FName anis("/Game/LowPolySkeleton/Skeleton_Mage/Anims/mage_run.mage_run");
		UAnimationAsset*animIns = Cast<UAnimationAsset>(StaticLoadObject(UAnimationAsset::StaticClass(), NULL, *anis.ToString()));

		this->GetMesh()->PlayAnimation(animIns, true);
	}
}

Go ahead sir! :slight_smile:
Dont be afraid using blueprints as finsl configurable class or animbp for your characters!
Blueprints is great tool to avoid hardcoding and if you use them smart, you never notice any performance difference between blueprint and c++
I mean obviously do not spawn 10000 blueprint actor with tick enabled in your world. If you need 10k ticking actor just use pure c++ classes (or nativize your bp)
But using animbp and exposing variables from your c++ class to bp for easy setup make sense :slight_smile:

Awesome! Anim blueprints is fantastic. What you think about mixing blueprints with c++?