Set AnimationBP via Code

Hello everybody,

I have a problem. I want to set the animationBP via Code. I 've found this workaround: :

static ConstructorHelpers::FObjectFinder<UAnimBlueprintGeneratedClass> AnimClass(TEXT(“AnimBlueprintGeneratedClass’/Game/Character/My_AnimBP.My_AnimBP_C’”));

I’ve tried. But this part doesnt work :frowning:

I get the error message “… cannot convert argument 1 from ‘UAnimBlueprintGeneratedClass *’ to ‘UObject *’ …”

Can someone help me? … please

Compiles on my end. Are you sure the error doesn’t happen on the next line?

I’m sure that the error is happen in this line. Cause, there is no other line after (for testing). . 8(

Now I’ve test it in Version 4.4.3. And It works! …

But it doesnt work in 4.5.1 … :frowning:

Do someone know, how can I set the AnimationBlueprint in 4.5.1 ? :confused:

Can i ask way you whould want to set it in code and not in the editor under the Amimation tab on the character Blueprint?
Edit: I belive it will work like this i have not had the opertunety to test this yet.

Also don`t forget to check if these are valid before you use them. :slight_smile:

Hope it helps.

In the constructor of your player class.

	if (Mesh)
		Mesh->AttachParent = CapsuleComponent;
// Note: It may want a UAnimInstance::
		static ConstructorHelpers::FObjectFinder<UAnimBlueprint> AnimClass(TEXT("AnimBlueprintGeneratedClass'/Game/Character/My_AnimBP.My_AnimBP_C'"));

Hey just did this for my inventory item widget and I can confirm that this method works in 4.5.1.
Just swap out the relevant template name and path for your needs.

	static ConstructorHelpers::FObjectFinder<USlateBrushAsset>DefaultImageBrush(TEXT("SlateBrushAsset'/Game/HUD_And_UI/InventoryUI/Brushes/ItemWidgetBrush.ItemWidgetBrush'"));
	if (DefaultImageBrush.Object)
		ItemImageBrush = DefaultImageBrush.Object;