As the title says, I am trying to access a camera component attached to a springarm socket that I have defined as follows
public:
UPROPERTY(EditAnywhere, Category = "camera")
USpringArmComponent* Springarm;
UPROPERTY(BlueprintReadWrite, Category = "Camera")
UCameraComponent* PlayerCamera;
the components are instantiated this way:
AXpCharacter::AXpCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer.SetDefaultSubobjectClass<UCustomMoveComponent>(ACharacter::CharacterMovementComponentName))
{
Springarm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));
Springarm->SetupAttachment(GetCapsuleComponent());
PlayerCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("PlayerCamera"));
PlayerCamera->SetupAttachment(Springarm,USpringArmComponent::SocketName);
}
When I attempt to access the Camera component as follows:
PlayerCamera->GetForwardVector()
I receive a NULL reference error, testing in blueprints confirms that ‘PlayerCamera’ is NULL
Why is this and how should I access the camera correctly?