Attach an actor to an character

I am newbie on unreal engine 4 so i am a lot confused about it.
I want to create a Skate/Weapon but i was stacked on the part where i need to join the Actor (skate for example) to the main Actor (the character) socket.
I searched on the forum but it did it more confused than i already thought.

How do i search and identify a specific actor like “the player”?
And will it give me the socket pointer or something?

How can i know information about various instanced actors without creating them inside one of another?

If you character has a skeletal mesh, you can create a socket and add it to one of the bones. The created socket’s local transform can be configured for whatever purpose you need it for. For example, a weapon added to a socket attached to the right hand, and a skateboard attached to a socket on the right/left foot.

Sorry for being too superficial. I already knew that i needed to use sockets.
i want, using the next function, connect an instance of an actor class to the skeletal mesh socket of the character:

AttachRootComponentTo(“how can i get the skeletal mesh of character here?”, FName(TEXT(“Right_Foot”)), EAttachLocation::SnapToTarget);
but how i asked, i don’t know i to get any information of the outside. Right now that function that i said is inside of the “Skate class”

If you are trying to attach something to your character, you can do it from within your character class like so:


UPROPERTY(VisibleDefaultsOnly, Category = "Skate) // This is so we can set the mesh in the editor
USkeletalMeshComponent* Skate;

And then create it in your constructor like so:


Skate = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Skate"));

And attach it in BeginPlay like so:


Skate->AttachTo(MESH_COMPONENT_OF_YOUR_CHARACTER_GOES_HERE, TEXT("SkateSocket"), EAttachLocation::SnapToTargetIncludingScale, true);

This is assuming that your attachable objects are skeletal meshes (which they should be) and if you don’t set up armatures in your modeling program then Unreal will generate a very rudimentary skeleton for your mesh on import which should work just fine for basic stuff.

If you need to attach the object from inside your skate class:

You’ll need to obtain a reference to your character class like so:


ASkateCharacter* CharacterReference = Cast<ASkateCharacter>(GetWorld()->GetFirstPlayerController()->GetCharacter());

You’ll also have to include your ASkateCharacter.h in the .cpp in order to use it properly.

Once you have a proper reference to your character, you can attach it the same as above by accessing the character mesh like this:


CharacterReference->YourSkeletalMeshComponent