How to use AttachComponentToComponent in C++?

Hello, Anyone can explain why using the blueprint is more efficient in this case, I mean when I attach the hairs using blueprint, the hairs is welded with headsocket in editor and in play mode, but with C++ I don’t know why only welded when playing the game… but in editor not welded. I can only think about the one thing that from where the BOOL condition comes in the AttachComponentToComponent node, I think this is responsible for this welding.

What I am trying to fix it: CODE:

//this must be in the constructor
auto Material = ConstructorHelpers::FObjectFinder<UMaterial>(TEXT("parrent material path"));
void initSkeletalMesh()
    if (Material.Object == nullptr) return;
    //create skin material
    SkinRef = GetMesh()->CreateDynamicMaterialInstance(0, Material.Object, NAME_None);
    GetMesh()->SetMaterialByName("Skin", SkinRef);
    //set master pose
    //attach hair
    SKMHair->AttachTo(GetMesh(),TEXT("Head"), EAttachLocation::KeepWorldPosition, true);

Another part related to this question:

[Related ISSUE][2]

[Related ISSUE 2][3]