加载资源文件中的 骨骼,动画,蒙太奇-----------------------------------------
FName anis("/Game/FirstPerson/Animations/FirstPerson_JumpLoop.FirstPerson_JumpLoop");
UAnimInstance*animIns = Cast<UAnimInstance>(StaticLoadObject(UAnimInstance::StaticClass(), NULL, *anis.ToString()));
FName ske("/Game/FirstPerson/Character/Mesh/SK_Mannequin_Arms_Skeleton.SK_Mannequin_Arms_Skeleton");
USkeleton*skeletal = Cast<USkeleton>(StaticLoadObject(USkeleton::StaticClass(), NULL, *ske.ToString()));
ani1->SetSkeleton(skeletal);
FName anis("/Game/FirstPerson/Animations/FirstPerson_JumpLoop.FirstPerson_JumpLoop");
UAnimInstance*animIns = Cast<UAnimInstance>(StaticLoadObject(UAnimInstance::StaticClass(), NULL, *anis.ToString()));
FName ske("/Game/FirstPerson/Character/Mesh/SK_Mannequin_Arms_Skeleton.SK_Mannequin_Arms_Skeleton");
USkeleton*skeletal = Cast<USkeleton>(StaticLoadObject(USkeleton::StaticClass(), NULL, *ske.ToString()));
ani1->SetSkeleton(skeletal);
UAnimMontage加载方法类似
动态加载并播放动画----------------------------------------------------------------
YourCharacter.h
UAnimSequence *Anim;
class YourCharacter : public ACharacter
{
...
UAnimSequence *Anim;
...
}
YourCharacter.cpp
AMyProject3Character::AMyProject3Character()
{
static ConstructorHelpers::FObjectFinder<UAnimSequence> anim(TEXT("AnimSequence'/Game/Mannequin/Animations/ThirdPersonJump_Start.ThirdPersonJump_Start'"));
Anim = anim.Object;
}
Playing animation:
bool bLoop = false;
GetMesh()->PlayAnimation(Anim, bLoop);