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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How to create an Anim Instance in C++?

Hey everyone!

As the question says, how do you create a c++ class derived from Anim Instance properly? Now I don't mean how to create the class itself (I know how to do that). I mean, what is the bare necessity code that I need to get it to compile so that I can create an Animation Blueprint derived from my custom anim instance, in the Editor?

I followed both of Rama's tutorials on the subject here and here, but whenever I try to create an Animation Blueprint derived from my custom anim instance the editor instantly crashes. The code compiles with no warnings or errors though. And this also happens when trying to reparent an Animation Blueprint to my custom anim instance.

So if anyone knows how to properly code it I would be very grateful to learn.

Here is my code

 // .h file
 #pragma once
 #include "Animation/AnimInstance.h"
 #include "MyAnimInstance.generate.h"
 UCLASS(transient, Blueprintable, hideCategories=AnimInstance, BlueprintType_
 class MYPROJECT_API UMyAniminstance : public UAnimInstance
      virtual void NativeInitializeAnimation() override;
      virtual void NativeUpdateAnimation(float DeltaTimeX) override;
      APawn* OwningPawn;
      UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
      float Speed;

here's the .cpp

 #include "MyProject.h"
 #include "MyAnimInstance.h"
 void URayAnimInstance::NativeInitializeAnimation()
      OwningPawn = TryGetPawnOwner();
 void UMyAnimInstance::NativeUpdateAnimation(float DeltaTimeX)
      Speed = OwningPawn->GetVelocity().Size();

What am I missing?

Product Version: UE 4.14
more ▼

asked Jan 22 '17 at 12:43 AM in C++ Programming

avatar image

239 21 12 28

avatar image poplockentaco Jan 22 '17 at 12:45 AM

in the .h I meant to type a ")" at the end of the UCLASS line, not a "_" That's just a typo and not my actual code.

avatar image poplockentaco Jan 22 '17 at 12:46 AM

Ugh and I meant to type "void UMyAnimInstance::NativeInitializeAnimation()" on line 4 of the .cpp. Sorry for the typos. I don't know how to edit questions after they've been asked.

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

1 answer: sort voted first

When I add Check code for OwningPawn, It's not crash again.

 if (OwningPawn)
     Speed = OwningPawn->GetVelocity().Size();
more ▼

answered Jun 20 '17 at 03:52 AM

avatar image

26 2 2

avatar image poplockentaco Jun 20 '17 at 04:49 AM

I forgot about this question. I had eventually figured it out, and it is as the above person said; you need to do a check to make sure the variable is valid before trying to do anything with it, otherwise it won't like you code. Thanks JinRiGuang for answering!

(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