Hi !
I am trying to import and play my animations entirely via C++ in order to understand a little bit about what happens behind the scenes when you use Blueprint animation. However, I can’t get it working, and I am going crazy ! Can anyone show me the light, please ? Here is my code:
================ MYCHARACTER.H =========================
/** SKELETAL MESH COMPONENT SETUP */
USkeletalMesh * P1SkeletalMesh;
UPhysicsAsset * P1PhysicsAsset;
/** BEGIN TO PLAY */
virtual void BeginPlay() override;
virtual void Tick(float DeltaSeconds) override;
/** ANIMATION SETTINGS */
TSubobjectPtr<UAnimSequence> Idle;
TSubobjectPtr<UAssetImportData> ImportData;
================ MYCHARACTER.CPP =========================
AMyCharacter::AMyCharacter(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
/** ================== SKELETAL MESH SETUP ======== */
/** Asset, Reference Obtained Via Right Click in Editor */
static ConstructorHelpers::FObjectFinder<USkeletalMesh> P1SkeletalMeshSource(TEXT("SkeletalMesh'/Game/BPCharacter/HeroTPP.HeroTPP'"));
static ConstructorHelpers::FObjectFinder<USkeleton> P1Skeleton(TEXT("Skeleton'/Game/BPCharacter/HeroTPP_Skeleton.HeroTPP_Skeleton'"));
static ConstructorHelpers::FObjectFinder<UPhysicsAsset> P1PhysicsAssetSource(TEXT("PhysicsAsset'/Game/BPCharacter/HeroTPP_PhysicsAsset.HeroTPP_PhysicsAsset'"));
/** Set Mesh From Source */
P1SkeletalMesh = P1SkeletalMeshSource.Object;
P1SkeletalMesh->PhysicsAsset = P1PhysicsAssetSource.Object;
P1SkeletalMesh->Skeleton = P1Skeleton.Object;
Mesh->SetSkeletalMesh(P1SkeletalMesh);
/** ================== SKELETAL MESH SETUP ======== */
/** ANIMATION SETTINGS */
Idle = PCIP.CreateDefaultSubobject<UAnimSequence> (this, TEXT("Idle"));
ImportData = PCIP.CreateDefaultSubobject<UAssetImportData> (this, TEXT("ImportData"));
Mesh->SetAnimationMode(EAnimationMode::AnimationSingleNode);
Idle->SetSkeleton(P1Skeleton.Object);
ImportData->SourceFilePath = FString(TEXT("AnimSequence'/Game/BPCharacter/Animations/Idle.Idle'"));
Idle->AssetImportData = ImportData;
Mesh->(Idle);
Mesh->PlayAnimation(Idle, true);
Mesh->InitAnim(true);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT(Idle->AssetImportData));
}
void AMyCharacter::BeginPlay() {
Super::BeginPlay();
}
void AMyCharacter::Tick(float DeltaSeconds) {}
Thanks !