Playing an animation through c++

,I am trying to play an animation through c++ while a counter is above 50. Note i am new to using ue4. Ive read many solutions to playing animations through the forums, but nothing seems to be working for me. Not sure what im doing wrong. Currently i am following this

and the line of code which finds the animation through the file browser is causing unreal to crash upon play.

I assume its because i am referencing the location improperly, dont know how to properly reference the location of my animation.

ThirdPersonDance is what i want to play.

A better workflow is to make the animation member variable a UPROPERTY and create a blueprint based on the class.
Let me know if you want any further information on how to do this.

Thanks! Ive found the correct path for the animation, but im not sure where/which constructor im supposed to put that code snippet into.

Ive read through this and assumed it may have been in EngineConstructors.cpp but i cant find that.

Hey! So i assume the const FCombatAnimationStruct is something you have created. Is there a pre existing struct like that?

At the top of your class you’re playing the animation in, you’ll find something like AMyClass::AMyClass(). This is the constructor. You need to put your FObjectFinder code in there.

Please mark the question as correct if I helped, thanks!

No clue why im getting errors. I assume when i create the function in the .h file i have to include the constructor code as well?

Doing this also breaks the timer i had set up.

Right click on your animation in the project browser, and select “Copy Reference” to get the correct path for the asset. Also, you can only use the FObjectFinder inside of a Constructor, so make sure you are using it in the Constructor.

Let me know if this solves the issue for you.

Hey there,

I struggled a lot with the playing anims from C++ a while back when I was working on a Dark Souls style template.
You can check out the code I ended up using to do the job here: UE4-MeleeTemplate/MGCharacter.cpp at master · calben/UE4-MeleeTemplate · GitHub

But the important snippet is:

float AMGCharacter::PlayCombatAnimation(const FCombatAnimationStruct Animation)
{
	if (!Animation.Animation)
	{
		UE_LOG(LogTemp, Warning, TEXT("NULL ANIMATION"));
		return 0.0f;
	}
	bIsCombatAnimating = true;
	PlayingAnimation = Animation;
	Controller->SetIgnoreMoveInput(true);
	PlayAnimMontage(Animation.Animation, Animation.AnimationSpeed);
	return Animation.Animation->GetPlayLength() / Animation.AnimationSpeed;
}

The best reference for playing animations through C++ is actually the ShooterGame.
Check out how they do the reload animations there.

Still looking for an answer.

Ah didn’t see this! There is not a preexisting struct, but you can grab the struct from the Github :slight_smile: