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:
I followed the step-by-step instructions and produced the following custom AnimInstance class:
.h
#pragma once
#include "CoreMinimal.h"
#include "BowAnimInstance.generated.h"
UCLASS(transient, Blueprintable, hideCategories = AnimInstance, BlueprintType)
class UBowAnimInstance : public UAnimInstance
{
GENERATED_UCLASS_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = StringPlacement)
FVector SkelControl_StringPos;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = StringPlacement)
FRotator SkelControl_StringRotation;
};
.cpp
#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:
I added some code to test the AnimInstance out, but the test for its existence came out as NULL.
.cpp
#include "Test_Game.h"
#include "Bow.h"
ABow::ABow()
{
// Set this actor to call Tick() every frame.
PrimaryActorTick.bCanEverTick = true;
// initialize components for bow
GetSkeletalMeshComponent()->SetSimulatePhysics(true);
stringGrabbed = false;
// Setup collision
GetSkeletalMeshComponent()->SetCollisionProfileName(FName("BlockAllDynamic"));
GetSkeletalMeshComponent()->bGenerateOverlapEvents = true;
}
void ABow::BeginPlay()
{
Super::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?
UPDATE:
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!