iamkrich
(iamkrich)
1
Hello! GetMesh() is not working for me and I do not understand why.
I included #include “GameFramework/Character.h”
Code Follows… should be straight forward
EBTNodeResult::Type UBTT_MeleeAttack::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
Super::ExecuteTask(OwnerComp, NodeMemory);
//Play attack Animation
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
return EBTNodeResult::Succeeded;
}
Is it because I am trying to call in in a Behavior Tree Task Node or something?
iamkrich
(iamkrich)
2
Wow this is driving me crazy. Here is how it works…
UAnimInstance* AnimInstance = OwnerComp.GetAIOwner()->GetCharacter()->GetMesh()->GetAnimInstance();
Does anybody have tutorial or can explain a way to play an animation from a behavior tree task node in C++?
Forsicen
(Forsicen)
3
Hi,
You really should have to. Here the code I use:
if (UseAnim)
{
MyPawn->PlayAnimMontage(UseAnim);
}
MyPawn is an
ACharacter*
UseAnim is an
UAnimMontage
This is the implementation for PlayAnimMontage (its a function I made)
float AMyCharacter::PlayAnimMontage(class UAnimMontage* AnimMontage, float InPlayRate, FName StartSectionName)
{
USkeletalMeshComponent* UseMesh = GetPawnMesh();
if (AnimMontage && UseMesh && UseMesh->AnimScriptInstance)
{
float time = 0.0f;
return UseMesh->AnimScriptInstance->Montage_Play(AnimMontage, InPlayRate);
}
return 0.0f;
}