I am trying to make a FPS out of the default TP project. The CONOPS of placing the FollowCamera a child of the Head and removing the CameraBoom is straightforward. My problem comes in when I try to attach the camera to the head in C++ vs. Blueprints. When using BP you have to place the Camera as a child of the Mesh and attach the head to the parent socket of the Camera. Straightforward in BP. But I don’t want to program in BP.
I cannot seem to get this working in C++. So far I have created a “headSocket” within the “head” bone and have written the following:
/*
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(RootComponent);
CameraBoom->TargetArmLength = 300.0f; // The camera follows at this distance behind the character
CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller
*/
// Create a follow camera
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->bEditableWhenInherited = true;
FollowCamera->bUsePawnControlRotation = true; // Camera does not rotate relative to arm
FollowCamera->SetupAttachment(GetMesh(), FName("headSocket"));
// I have also tried
// FollowCamera->AttachTo(GetMesh(), "headSocket");
No type of attachment I can perform seems to work.