C++ specify mesh for MyPawn->PlayAnimMontage

Hi,

(actually it’s the setup from Shooter Game example)
I have a character which has two meshes (1st Person & 3rd Person).
When I do MyPawn->PlayAnimMontage(myMontage) the animation is played on the default mesh instead of Mesh1P.

How can I determine which mesh to choose for this case?

I cannot see how its done in shooter example.

Thanks a lot

Hi xhallix,

You can try to override this function in your character:

YourCharacter.h

virtual float PlayAnimMontage(class UAnimMontage* AnimMontage, float InPlayRate = 1.f, FName StartSectionName = NAME_None) override;

YourCharacter.cpp

#include "Animation/AnimInstance.h"

...

float YourCharacter::PlayAnimMontage(class UAnimMontage* AnimMontage, float InPlayRate, FName StartSectionName)
{
	UAnimInstance * AnimInstance = (Mesh) ? Mesh->GetAnimInstance() : NULL;
	if (AnimMontage && AnimInstance)
	{
		float const Duration = AnimInstance->Montage_Play(AnimMontage, InPlayRate);

		if (Duration > 0.f)
		{
			// Start at a given Section.
			if (StartSectionName != NAME_None)
			{
				AnimInstance->Montage_JumpToSection(StartSectionName, AnimMontage);
			}

			return Duration;
		}
	}

	return 0.f;
}

Mesh - put your mesh here

Hope this helps!

yes that would definitly be a good idea!
But I wonder how this is managed in the shooter project?
I think they did not overwrite any function, at least from what I saw.

Maybe you can give me a hint how it is done in the shooter example?

old question! but they did do this in the shooter example. see AShooterCharacter::PlayAnimMontage