How to properly attach a camera component to a socket in a character mesh?

I use in the constructor:


FPSCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FPSCamera"));
    FPSCamera->SetRelativeLocation(FVector(0.0f, -20.0f, 55.0f));
    FPSCamera->SetRelativeRotation(FRotator(0.0f, 0.0f, -90.0f));
    //FPSCamera->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale);
    FPSCamera->SetupAttachment(GetMesh());

And in the BeginPlay:


FPSCamera->AttachToComponent(GetMesh(), FAttachmentTransformRules(EAttachmentRule::KeepRelative, EAttachmentRule::KeepRelative, EAttachmentRule::KeepRelative, true), "FPVCamera");

The camera component should follow the socket of the mesh. I’m unable to do that because the camera doesn’t follow the socket. I cannot parent the camera to the mesh in C++. How to do that?

I use:


FPSCamera->AttachToComponent(GetMesh(), FAttachmentTransformRules(EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, EAttachmentRule::KeepRelative, true), TEXT("FPVCamera"));

It parents the camera to the mesh, but it is not snap to the socket - it is not moving with the socket; it is stiff.

Did you find a way to get this to work ?