x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.10
Tags:
more ▼

asked Feb 03 '16 at 07:41 PM in C++ Programming

avatar image

omigamedev
85 9 7 17

avatar image rantrod Feb 04 '16 at 03:04 AM

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?

avatar image omigamedev Feb 04 '16 at 07:28 AM

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.

avatar image omigamedev Feb 04 '16 at 02:34 PM

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);
 }
 
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Feb 18 '16 at 03:37 PM

avatar image

omigamedev
85 9 7 17

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Feb 04 '16 at 05:07 AM

avatar image

Shadowriver
37.1k 935 172 1116

avatar image omigamedev Feb 04 '16 at 07:37 AM

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.

avatar image MickD777 Feb 04 '16 at 04:10 PM

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...

avatar image Shadowriver Feb 04 '16 at 04:36 PM

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 Michael mentioned

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question