Attach actor C++ class with it's mesh to socket with c++

I;m trying to do something simple, attach an actor with it’s mesh to the default character skeleton with c++

There are no clear simple tutorials anywhere to follow my simple example so I decided to ask here.

How would I go about this. There are many examples, all confusing with different walks each different, so I decided to ask here.

So I created a socket on the skeletal part of the hand of the main default third person character that comes with a skeletal mesh.

I created a C++ actor class and I want to attach the actor with it’s mesh to the hand of the character.
I created a static mesh within the actor class.

Header file
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Engine/StaticMesh.h"
#include "Components/StaticMeshComponent.h"
#include "MyAc.generated.h"

UCLASS()
class MYPROJECT3_API AMyAc : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AMyAc();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;
    void Cone(AActor* Player);  

private:
    UStaticMesh* Mesh;
    UStaticMeshComponent* MeshComp;
};

Cpp file

#include "UObject/ConstructorHelpers.h"
 #include "MyAc.h"

// Sets default values
AMyAc::AMyAc()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

    static ConstructorHelpers::FObjectFinder<UStaticMesh>CMesh(TEXT("StaticMesh'/Game/Meshes/StaticMesh1.StaticMesh1'"));
    Mesh = CMesh.Object;
    if (Mesh == nullptr)
     {  
     UE_LOG(LogTemp, Warning, TEXT("ERROR FINDING STATIC MESH"));
     }
      
     else
     {
      MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(FName("StaticMeshComponent"), true); 
      MeshComp ->SetStaticMesh(Mesh);
     }
    
}

// Called when the game starts or when spawned
void AMyAc::BeginPlay()
{
	Super::BeginPlay();
	
}


// Called every frame
void AMyAc::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

So I used constructor helpers to locate the mesh.
No errors so far to this point.
Now I’m suppose to have a function with the attachment part that I left out because I tried different ways and it does not work.

within the function I’m suppose to have I used something like:

Mesh->AttachToComponent(this, FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true), TEXT("hand"));

But this will not work because I need to refrence the Character somehow, what is it called, Character, Player ?
Attach to what ??

Do I also need to spawn the actor class ?
Do I need to set the mesh to root component.
I am attaching what, the mesh directly, the component of the mesh or the actor it’s self ?

I don’t want this in blueprint at all, the item I’m attaching is a simple actor with a simple mesh, has no coding, it’s not a weapon, just a simple mesh for practice for me to see how it works.

So when I hit play I want to see the actor with it’s mesh attached to the skeletal socket of the hand.
I will use key bindings later but for now I just want to see it attached at begin play.

I recommend you first prototype and try different AttachTo nodes in Blueprint. Once you get the logic right then you can transfer code easily to c++

I solved my problem, got it working in C++, only problem is that the item attached to the hand that is spawned on the socket of the hand of the character, this item that is attached does no collide with other objects around it.

For example I attach a mesh like a long rod to the hand of the character on the socket, and the character has the actor item on his socket located on his hand, and I make the character run forward into a wall with the rod put forward say like a sword and the character is charging at the wall running towards the wall, but this item attach does not collide with other objects in the world. So the rod, sword if you will will go thru the wall.

So it seems the actors that I attach to the socket do not collide with other shapes, meshes, actors and so on in the world, the item held on the socket of the character simply go’s thru other items like a ghost.

I tried everything in collision settings for the actor attached to socket, I observed it does not let me set the physical simulate object tab, but I take it if I manage some how to activate that the character would be stuck where the object is for haps maybe.

So anyway, the collisions of the objects attached to sockets don’t work, there are no collisions.
Must be some blue print stuff I think, and for now I only want to deal with C++ if I can code the object in C++ and make it collidable, like a hammer if you struck with a hammer on a cube the cube should shake or collide with the hammer in a physical simulated way.