Download

Attach camera to Skeletal Socket

I started with 3rd Person Character Template in C++ and tried to add some functionality. First, I created a new class called PlayerCharacter, derived from template character (ProjectName_Character). I also created a socket (headSocket) in the default player Mesh (SK_Mannequin). Then I added a camera (cpp_HeadCamera) to PlayerCharacter, and successfully attached it to the mesh using GetMesh(), but now I can’t figure out how to attach it to headSocket. I tried several solutions I saw here, but with no results.

I created a blueprint to derived from PlayerCharacter, added a new camera (bp_HeadCamera) and attached to headSocket. It woks flawlessly. As the character breathes, the camera follows his movements.

How can I attach cppHeadCamera to headSocket?



AFTPShooter_PlayerCharacter::AFTPShooter_PlayerCharacter() {
	FName fnHeadCameraSocket = TEXT("headSocket");
	cpp_HeadCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("HeadCamera"));
	cpp_HeadCamera->AttachTo(GetMesh(), fnHeadCameraSocket); } //Also tried with "EAttachLocation::xxx"