I want to attach the root component of my equipable class to the right hand socket on the game character, how do I do this? I know I need to use
Mesh
from GameCharacter.cpp, but because I need to access this from Equipable.cpp I don’t know how to do it. Thanks.
Equipable.cpp
RootComponent->AttachTo(??? ,"hand_rSocket");
Jambax
(Jambax)
2
From the ShooterGame sample:
ShooterWeapon.cpp
void AShooterWeapon::AttachMeshToPawn()
{
if (MyPawn)
{
// Remove and hide both first and third person meshes
DetachMeshFromPawn();
// For locally controller players we attach both weapons and let the bOnlyOwnerSee, bOwnerNoSee flags deal with visibility.
FName AttachPoint = MyPawn->GetWeaponAttachPoint();
if( MyPawn->IsLocallyControlled() == true )
{
USkeletalMeshComponent* PawnMesh1p = MyPawn->GetSpecifcPawnMesh(true);
USkeletalMeshComponent* PawnMesh3p = MyPawn->GetSpecifcPawnMesh(false);
Mesh1P->SetHiddenInGame( false );
Mesh3P->SetHiddenInGame( false );
Mesh1P->AttachTo(PawnMesh1p, AttachPoint);
Mesh3P->AttachTo(PawnMesh3p, AttachPoint);
}
else
{
USkeletalMeshComponent* UseWeaponMesh = GetWeaponMesh();
USkeletalMeshComponent* UsePawnMesh = MyPawn->GetPawnMesh();
UseWeaponMesh->AttachTo(UsePawnMesh, AttachPoint);
UseWeaponMesh->SetHiddenInGame( false );
}
}
}
The ‘GetWeaponAttachPoint()’ function just returns the name of the socket you want to attach to in the Pawn.