Moving camera to weapon sight

Hi everyone,

I got stuck with my approach to aiming down sights. I’ve set up my first person arms mesh to be a child of the camera. Added a socket on the right hand of the skeleton to which I attach my weapon and there is a socket in the weapon used to signal the point at which the camera should sit during aiming down sight. When the players aims holding left click what I’m trying to do is to calculate the offset of the sight socket to the root of the FPP Mesh while on the aiming down sights pose and move the camera based on that.

Here is the code:

    FTransform HandToComponent;


    FTransform BoneTransform;

    USkeletalMeshComponent* Mesh1P = CarryingPlayer->Mesh1P;

    // Get transform to weapon attach socket space
    HandToComponent *= FirearmMesh->GetSocketTransform(FName("sight_point_socket"), RTS_ParentBoneSpace);
    HandToComponent *= Mesh1P->GetSocketTransform(Firearm->GetCarrySocket(), RTS_ParentBoneSpace);

    // Get transform from the right hand bone relative to component (root bone)
    FName CurrentBoneName = FName("hand_r");
    while (CurrentBoneName != NAME_None)
        ArmsADSIdleAnimSequence->GetBoneTransform(BoneTransform, Mesh1P->GetBoneIndex(CurrentBoneName), 0.0f, true);
        HandToComponent *= BoneTransform;
        CurrentBoneName = Mesh1P->GetParentBone(CurrentBoneName);

    return HandToComponent;

Then I’m just adding the translation to the FPP Mesh component relative to the camera. The sockets are set up properly but the camera ends up to the right of the actual intended point.
If I switch the X and Y coordinates in the resulting translation the result seems accurate even though I’m not accounting for slight rotation. This leads me to believe that there is a problem with the weapon attach socket on the right hand (GetCarrySocket on code) since it is rotated 92 degress around the Z axis (switching X and Y), maybe the transform compositions are not taking this in account somehow?

Thanks very much for reading.