With the following C++ code
// BaseCharacter.h
UCLASS()
class MYGAME_API ABaseCharacter : public ACharacter
{
GENERATED_BODY()
public:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
class USpringArmComponent* SpringArm;
// ...
}
// BaseCharacter.cpp
ABaseCharacter::ABaseCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));
SpringArm->TargetArmLength = 0.f;
SpringArm->bUsePawnControlRotation = true;
SpringArm->bInheritRoll = false;
SpringArm->bEnableCameraLag = true;
SpringArm->CameraLagSpeed = 20.f;
SpringArm->CameraRotationLagSpeed = 0.f;
SpringArm->SetupAttachment(RootComponent);
}
SpringArm is always None when referenced in a Blueprint inherited from my BaseCharacter class. For example the following
Always gives:
Blueprint Runtime Error: “Accessed None trying to read property SpringArm”. Blueprint: BP_BaseCharacter Function: Construction Script Graph: UserConstructionScript Node: Set SpringArmInitialLocation
At any other point in the blueprint, if I try to access SpringArm, I get the same error.
Looking in the component hierarchy, everything seems to look perfectly fine.
I’ve tried rebuilding the project several times and a few different UPROPERTY specifies; no luck
EDIT:
This is also happening in C++. The following code crashes the engine since the pointer is none
// Called when the game starts or when spawned
void ABaseCharacter::BeginPlay()
{
Super::BeginPlay();
// crashes game due to null pointer exception
UE_LOG(LogTemp, Warning, TEXT("%s"), *SpringArm->GetName())
}