Hello,
I run into some issues trying to set the relative location of my camera in c++, the camera would always be placed relative to 0,0,0 in world coordinates.
I figured, that this is probably due to the parent of the camera not being set, before the setRelativeLocation took place and decided, to set the parent of my camera myself with the AttachTo() function of USceneComponent.
FirstPersonCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
// Makes sure the UCapsuleComponent is the parent of this Camara
if (GetCapsuleComponent())
{
FirstPersonCamera->AttachTo(GetCapsuleComponent());
}
The compiling of this code fails, because it can’t convert from UCapsuleComponent* to USceneComponent*, but according to the Unreal Engine 4 Documentation:
Somewhere along the way UCapsuleComponent inherits from USceneComponent, so this should normally work right?
Note:
The same code works, if I replace UCapsuleComponent with a USkeletalMeshComponent, by using GetMesh(), but doesn’t deliver the desired results. (I will deactivate the mesh and it’s children on camera Swap and both cameras have the relative location problem)