Using SetAnimInstanceClass() to pass AnimBlueprint from DataAsset

I’m building out a character setup where I can assign a Character DataAsset object which contains a reference to some base information such as **Mesh Anmations **and meta data.

I already have the player setup to use the Character class and switching between various DataAssets allow me to switch the player between different meshes such as Goblin, Human, Orgre (The test cases I’m using).

When I try to assign the **AnimBlueprint **for the mesh it fails and leaves the character stuck in a T-Pose. I can fudge this at runtime by manually selecting the **Animblueprint **in the dropdown option on the instance so I can confirm that once configured it does work.

Here’s what I have setup:

The **DataAsset **named MW_CharacterData has the following:



UCLASS(BlueprintType)
class CHARACTER_API UMW_CharacterData : public UDataAsset
{
    GENERATED_BODY()

public:
    /* Visual Mesh */
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Mesh")
        USkeletalMesh* Mesh;

    /* Animation BluePrint */
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Mesh")
        UAnimBlueprint* Anim;
};


The **CharacterBase **Class named **MWCharacterBase **has the following (snipped)



AMWCharacterBase::AMWCharacterBase()
{
     // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;

    //Get the character data asset
    DataAsset = CreateDefaultSubobject<UMW_CharacterData>(TEXT("DataAsset"));
}

void AMWCharacterBase::BeginPlay()
{
    Super::BeginPlay();

    // Set Mesh From DataAsset
    GetMesh()->SetSkeletalMesh(DataAsset->Mesh, false);
    GetMesh()->SetAnimationMode(EAnimationMode::AnimationBlueprint);
    GetMesh()->SetAnimInstanceClass(DataAsset->Anim->GetClass());
}


The Mesh assignment works perfectly fine, I can switch data assets and have the character appear as the correct mesh.

My issue seems to be coming from **GetMesh()->SetAnimInstanceClass(DataAsset->Anim->GetClass()); **which results in the runtime Anim pointing to **AnimBlueprint **rather than the actual assigned animation set.

I have also tried **GetMesh()->SetAnimInstanceClass(DataAsset->Anim->GetBlueprintClass()); **to no avail, it instead points to AnimBlueprintGeneratedClass.

Had this same issue.

m_SkeletalMeshComp->SetAnimInstanceClass(m_AnimBP->GetAnimBlueprintGeneratedClass());

This worked for me.

Cheers

1 Like