Why I can't attach the mesh to the socket ?

Hi,

I’m trying to attach a meshcomponent to a socket of the skeletalMesh for my character. But I don’t why it doesn’t work ! Can someone help me ?
I tried different way, but nothing works for me.
Please help me !

Here my construct of my character class (cpp) :



    EquippedObject = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("EquippedObject"));
    EquippedObject->SetStaticMesh(Asset);
    EquippedObject->AttachTo(GetMesh(), FName("RightHandSocket"), EAttachLocation::SnapToTargetIncludingScale, true);
TEXT("RightHandSocket"));
    EquippedObject->SetGenerateOverlapEvents(true);
    EquippedObject->SetCollisionProfileName("OverlapAll");


I also tried :



    //EquippedObject->AttachToComponent(GetMesh(), FAttachmentTransformRules(EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, EAttachmentRule::KeepRelative, true), TEXT("RightHandSocket"));


And :



    //EquippedObject->SetupAttachment(GetMesh(), FName("RightHandSocket"));


Here, my socket :

And, on the player character inherited from my c++ character :
child.PNG

It’s OK !
It doesn’t work in the constructor but it works in the beginplay function !

1 Like