Attaching Camera to Head Socket

Hello everyone, I am currently trying to create my character controller. I have been searching online for this solution, but there’s not a whole lot on this except for vague responses.

In a TPP BP project, I am able to drag the camera into the mesh so that I can attach the camera to the Head Bone.

In a TPP C++ Project I am not able to drag the camera to make it a child of the Mesh. On top of that, I can’t access the ‘Parent Socket’ to choose the Head Bone.

So I added a socket to the Head Bone. It is called “HeadSocket.” What I want to do now is attach the Camera to the “HeadSocket” so that I am able to have a full body awareness using C++ instead of BP.

I created the Camera:

CameraComp = CreateDefaultSubObject<UCameraComponent>(TEXT(“CameraComp”));
CameraComp->AttachTo(GetMesh());
CameraComp->bUsePawnControlRotation = true;

If anyone knows the way, you’d be my Hero!

Try



CameraComp->AttachTo(GetMesh(), "HeadSocket");


2 Likes

Thank you very much, @ItsaMeTuni ! That worked for me! I was so close… funny thing is that I had tried that before but I must have spelled the Socket Name wrong -_-

Can i ask a question? how can you get the name of the mesh if it’s not set? or just set after set up the BP?

This helped, thanks, actually in UE5 it’s a bit different:

Camera->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetIncludingScale, “Head”);

3 Likes

Awesome, thanks!