Why I cannot use a C++ UAnimInstance directly?

I’m not able to set my SkeletalMeshComponent derived class to use a UAnimInstance derived class but I’m forced to use a UAnimBlueprintGeneratedClass even though they both derive from UAnimInstance?
This means that I can create UmyAnimInstance, create a BP that extends it and the set the BP generated class (BP_myAnimInstance_C) bat to C++ to assign it to the SkeletalMeshComponent.
Is there any reason?
I can even select from the editor my native class, but then it’s no used/updated at runtime, so the animation is stuck, and this is probably due to the USkeletalMeshComponent that checks everywhere whether AnimBlueprintGeneratedClass is a child of UAnimBlueprintGeneratedClass.
I’m disappointed.

To understand clearly: you can create your own UAnimInstance derived class, then create an AnimBP in the editor based on it, and assign it to your character which uses a SkeletalMeshComponent derived class. At what point does this break down? Is it that you don’t want to use an AnimBP at all?

Blueprints does not exist in compile time, it’s not C++ code which can be compiled to native code (machine code of CPU), that why code can’t directly reference it in C++ because compiler does not have anything to refrence to, in matter of fact it’s can’t even guarranty that it will be able to refrence it in future because blueprint file might be missing or something. So what you doing is referencing asset object of blueprint (UBlueprint or in your case UAnimBlueprint) which will make engine load the asset in runtime (keep in mind runtime also means in editor) and then you can get generated (by blueprint virtual machine) UClass* to UAnimInstance of that blueprint.

You can get UClass* of blueprint class a lot easier by creating UClass* or TSubclassOf variable and set it in defaults of blueprint, but i know it does not fit to all solutions and it requires to make a blueprint.

Epic currently working on Blueprint to C++ compiler which might allow to directly reference to blueprint classes, but animation blueprint is little bit diffrent, so not sure how it will go with it

The problem is that the editor from 4.7 probably made a big change in the native code management, now from the editor you cannot change parameters of the components created in C++ code.

I created a Pawn in C++ that creates all it’s components natively, including a native SkeletalMeshComponent.

Now what I’d like to do is to keep everything clean and create a C++ AnimInstance and reference it directly to the SkeletalMeshComponent in C++ without using the editor at all.

This is not possible because I have to create a BP that derives my AnimInstance and then load the asset in the skeletal mesh and use the generated class.

This seems to me to just add a reference to a blueprint that I don’t use at all since the animation is handled via C++.

I hope it’s more clear now.

But did Epic change the behavior of the Editor withe way it manages C++ components? Why I cannot modify components created natively when I derive an native actor? This is basically the root of all the problems I have. Before 4.7 you was basically able to change the state of a component from a C++ derived BP, now everything is grayed out.

At the moment this is the only way I have found to make it work. When I create an AnimationBlueprint based on my AnimInstance it fits the UAnimInstance derived class into a UAnimBlueprintGeneratedClass which is the weirdest thing I have seen in a while. This is then why this code works, even though is wrong in so many ways.

UTS_HandSkeletalMeshComponent::UTS_HandSkeletalMeshComponent()
{
    ConstructorHelpers::FObjectFinder<USkeletalMesh> HandSkeletalMesh(TEXT("SkeletalMesh'/Game/Meshes/Hand.Hand'"));

    if (HandSkeletalMesh.Succeeded())
    {
        SetSkeletalMesh(HandSkeletalMesh.Object);
        SetCollisionProfileName("NoCollision");
    }

    AnimBlueprintGeneratedClass = 
        static_cast<UAnimBlueprintGeneratedClass*>
        (UTS_HandAnimInstance::StaticClass());
    AnimBlueprintGeneratedClass->TargetSkeleton = SkeletalMesh->Skeleton;
    InitAnim(true);
}

I think I see you problem, and yes, you can modify components directly created in C++ in the editor Blueprint version of your class. The component you create must be under a UPROPERTY() and you have to add an edit flag, like you do other properties, to actually see or be able to edit those components.

You can use EditAnywhere, or VisibleAnywhere, EditDefaultsOnly, etc…

You could not do that since i remeber, not sure why, maybe there some limitation in current form of reflection system :> but there work around that mentioned

Cool it seems that this has been fixed in 4.11 and AnimClass has been added to SkeletalMeshComponent to take care of native animations in C++. It also seems the pipeline has changed a bit with the introduction of FAnimInstanceProxy.