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"

GetSkeletalMeshComponent()->GetAnimInstance() returns NULL

Hello! I am creating a Bow and Arrow for VR. The bow was created in C++ and was inherited from the SkeletalMeshActor. The actual mesh is populated when its instance is dropped in the level. I have a bone on the bow string so my player can pull it back with the motion controllers. To accomplish this, I am using a custom AnimInstance class to set custom variables for that bone's location. The tutorial below helped me accomplish this:

Rama's Tutorial

I followed the step-by-step instructions and produced the following custom AnimInstance class:


 #pragma once
 #include "CoreMinimal.h"
 #include "BowAnimInstance.generated.h"
 UCLASS(transient, Blueprintable, hideCategories = AnimInstance, BlueprintType)
 class UBowAnimInstance : public UAnimInstance
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = StringPlacement)
         FVector SkelControl_StringPos;
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = StringPlacement)
         FRotator SkelControl_StringRotation;


 #include "Test_Game.h"
 #include "BowAnimInstance.h"
 UBowAnimInstance::UBowAnimInstance(const FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer)
     // default values
     SkelControl_StringPos = FVector(0, 0, 0);
     SkelControl_StringRotation = FRotator(0, 0, 0);

On the BP side, I created the bow's Animation BP and reparented it to my custom AnimInstance class. I can successfully access those variables in the Animation BP.

In the level, my bow instance has the skeletal mesh attached and notes to use the Animation BP and the Anim Class:

alt text

I added some code to test the AnimInstance out, but the test for its existence came out as NULL.


 #include "Test_Game.h"
 #include "Bow.h"

     // Set this actor to call Tick() every frame.
     PrimaryActorTick.bCanEverTick = true;
     // initialize components for bow
     stringGrabbed = false;
     // Setup collision
     GetSkeletalMeshComponent()->bGenerateOverlapEvents = true;
 void ABow::BeginPlay()
     if (GetSkeletalMeshComponent()->GetAnimInstance() == NULL)
         UE_LOG(LogTemp, Warning, TEXT("No existing animation."));

Is there something obvious I have forgotten to do to access the AnimationInstance I have created?


In addition, this is my Animation Blueprint for the bow. I'm fairly new to using this system, so be kind if the problem is obvious! :P

alt text

Product Version: UE 4.16
bowanimbp.png (565.4 kB)
more ▼

asked Dec 18 '18 at 11:41 PM in C++ Programming

avatar image

1 2 2

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

1 answer: sort voted first

Hi, this is most likely because actors are not guaranteed to exist at construction time (and they most likely will not, the world might not exist at that point). All actors will be initialised by the time BeginPlay is called, which I believe is the most suitable for what you are trying to achieve (use BeginPlay instead of the constructor).

more ▼

answered Dec 19 '18 at 12:35 PM

avatar image

86 1 4 3

avatar image EngineerDveloper Dec 19 '18 at 04:43 PM

Hi Lupix. Thanks for your response. In my code above, I'm already checking the "GetAnimInstance()" in BeginPlay with the same results.

I also placed this check in the function when I grab the string in-game, but the instance still returns NULL.

avatar image Lupix Dec 19 '18 at 04:50 PM

Oh, my bad. I did not see the lower part of your code block. Having said that, I also fail to see what would be causing this. I've looked around and it seems quite some people are having a similar issue. I may be able to get back to you with more information when I get the time to check how I've done it in my projects.

(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