I am having an issue when setting the RelativeLocation of my UCameraComponent.
// FPSCharacter.h
UPROPERTY(VisibleDefaultsOnly, Category = Camera)
UCameraComponent* FirstPersonCameraComponent;
// FPSCharacter.cpp
AFPSCharacter::AFPSCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
// Create the first person camera
FirstPersonCameraComponent = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>(this, TEXT("FirstPersonCamera"));
FirstPersonCameraComponent->AttachParent = GetCapsuleComponent();
// Position the camera a bit above the eyes
FirstPersonCameraComponent->RelativeLocation = FVector(0, 0, 40.0f + BaseEyeHeight);
// Allow the pawn to control rotation.
FirstPersonCameraComponent->bUsePawnControlRotation = true;
}
As you can see the location is still 0,0,0 and the camera is showing up below the character’s waist.
I have also tried using SetRelativePosition().
However, neither approaches are working.
It has worked a couple times, but for the most part it doesn’t. Which is leading me to think this might be a bug.
Not sure wahts going on here, maybe there something wrong attachment, considering capsule is root, try using RootComponent insted of GetCapsuleComponent().
But if you find don’t find fix for that, here work around. Insted of suing camera components, override CalcCamera function which sets camera position of view target (by default it pick camera component)