How can I attach a blueprint weapon to socket?

I have C++ class of my character and also I have a blueprint generated class of weapon. How can I attach the weapon? I still can’t figure out, how can I create components of blueprint generated classes.

Thank you.

I recommad you to create (atleast dummy) base class for weapon with functions and varables that your weapon needs, it will be easier for you to operate blueprint made weapons based of that class in C++ this way.

In that weapon base class, you could have varable:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Weapon)
UStaticMesh WeaponMesh;

And in defaults of weapon based class you will see mesh selector, you set mesh of a weapon, whih later you can read and apply to component in character

is how I attach my weapon to the FPS Mesh in my project.
I created a socket on the bone of the mesh and then spawn the Weapon Actor and then attach it.
Like this. (See Link for better view.)

bool AMyProjectWeapon::AttachWeaponToPawn(APawn* WeaponOwner, FString SkeletalCompName)
{
	OwningPawn = WeaponOwner; // Sets the owner of this weapon. (Note: OwningPawn  is a APawn* member in my weapon class.)
	SetOwner(OwningPawn); // AActor::SetOwner(APawn*);

       // A method i created to get any skeletal component from the owning pawn. (Could be made a template to function to get any type.)
	USkeletalMeshComponent* ArmMesh = GetPawnSkeletalComp(SkeletalCompName); 

	if (ArmMesh) // Check to see if our rig Skeletal Mesh Component is good.
	{
                // AActor::AttachRootComponentTo(..)
		AttachRootComponentTo(ArmMesh, FName(TEXT("WeaponPoint")), EAttachLocation::SnapToTarget); // Attach the root component of our Weapon actor to the ArmMesh at the location of the socket.
		return true; // Note: We can only assume it is attached, since epic did not provide a return value.
	}
	else
	{
		return false;
	}
}

USkeletalMeshComponent* AMyProjectWeapon::GetPawnSkeletalComp(FString ComponentName)
{
	TArray<UActorComponent*> Components; // Array for Pawns components
	USkeletalMeshComponent* ArmMesh = NULL; // Will hold the skeletal mesh we want

	if (OwningPawn)
		OwningPawn->GetComponents(Components); // Get the components from the owning pawn

	for (UActorComponent* Comp : Components)
	{
		ArmMesh = Cast<USkeletalMeshComponent>(Comp); // Cast any component to Skeletal Comp.
		if (ArmMesh) // If we have a skeletal mesh
		{
			if (ArmMesh->GetName() == ComponentName) // Check to see if its the one we want.
				return ArmMesh;
		}
	}

	return NULL; // Finished with out finding the component we wanted.
}

Hope it helps.