AttachTo and UCapsuleComponent

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)

Thank you for your quick answer!

I indeed forgot the include. (derpy me)
I did not know, that missing conversions are an indicator for this.

Have a nice day!

Have you tried this?

 FirstPersonCamera->SetupAttachment(GetCapsuleComponent());

If,i am not wrong then,AttachTo() function has been deprecated now.
Also,make sure that,you have this header included.

#include "Components/CapsuleComponent.h"

Maybe,you are getting that conversion error because,you have not included CapsuleComponent.h header?