Error when changing skeletalmesh with new animblueprint at runtime

How to change skeletalmesh and animblueprint at runtime?

I can change skeletal mesh, but changing of animblueprint always fail.

class .h

UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
TSubobjectPtr<USkeletalMeshComponent> CurrentMesh;

UPROPERTY(EditDefaultsOnly, Category = Mesh)
USkeletalMesh* FlagMesh;

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Animation)
UAnimBlueprint* FlagVIM;

class .cpp

CurrentMesh->SetSkeletalMesh(FlagMesh); //works
CurrentMesh->SetAnimClass(FlagVIM->GetAnimBlueprintGeneratedClass()); //fails

Also i have tried:

CurrentMesh->SetAnimClass(FlagVIM) //compile failed because UAnimBlueprint* is not a UClass*

And also if i set

UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Animation)
UAnimBlueprintGeneratedClass* FlagVIM;

CurrentMesh->SetAnimClass(FlagVIM) //fails inside SetAnimClass() function

How to change it right?

I Might be completely on the wrong track here, but try to get all the Blueprints during your initialization via:

 AFriendly1::AFriendly1(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
    {
    
        static ConstructorHelpers::FObjectFinder<USkeletalMesh> FriendlyMesh(TEXT("SkeletalMesh'/Game/Character/HeroTPP.HeroTPP'"));
        	static ConstructorHelpers::FObjectFinder<UBlueprint> MeshAnimBluePrint(TEXT("AnimBlueprint'/Game/Character/HeroTPP_AnimBlueprint.HeroTPP_AnimBlueprint'"));
Mesh->SkeletalMesh = (USkeletalMesh*)FriendlyMesh.Object;
Mesh->AnimBlueprintGeneratedClass = (UAnimBlueprintGeneratedClass*)MeshAnimBluePrint.Object;
    
    ..........
    }

and then just update the properties when needed during runtime by referencing to these.

This is strange way, i do not want to find it, i want to set it and use it.
tnx

Still the same in 4.1.
May be this is a bug?

Hello,

Thank you for your report. We were not able to investigate this on the engine version you reported, but there have been many version changes to UE4 since this question was first posted. With a new version of the Engine comes new fixes and it is possible that this issue has changed or may no longer occur. Due to timetable of when this issue was first posted, we are marking this post as resolved for tracking purposes.

If you are still experiencing the issue you reported in the current engine version, then please respond to this message with additional information and we will investigate as soon as possible. If you are experiencing a similar, but different issue at this time, please submit a new report for it.

Thank you.