hey guys, I’m making an FPS game and facing a problem, I need the weapon on the Locally Controlled Client to connect to the “RightHandSocket” of the “FPSMesh” , and for other clients, to the socket with the same name, but a different mesh, (I have 1 skeleton for 2 meshes). Problem: On other clients, weapon is attached to FPSMesh, but not GetMesh() and I cant figure out why, what am I doing wrong?
void UCombatComponent::EquipWeapon(class AWeapon* WeaponToEquip)
{
if (Character == nullptr || WeaponToEquip == nullptr) return;
if(EquippedWeapon)//if is not null
{
EquippedWeapon->Dropped();
}
EquippedWeapon = WeaponToEquip;
EquippedWeapon->SetWeaponState(EWeaponState::EWS_Equipped);
if (GetOwnerRole() == ROLE_Authority || (GetOwnerRole() == ROLE_AutonomousProxy))
{
const USkeletalMeshSocket* HandSocket = Character->GetFPSMesh()->GetSocketByName(FName("RightHandSocket"));
if (HandSocket)
{
HandSocket->AttachActor(EquippedWeapon, Character->GetFPSMesh());//attaching weapon to a socket
}
}
}
void UCombatComponent::OnRep_EquippedWeapon()//client
{
if (EquippedWeapon && Character)
{
EquippedWeapon->SetWeaponState(EWeaponState::EWS_Equipped);
const USkeletalMeshSocket* HandSocket = Character->GetMesh()->GetSocketByName(FName("RightHandSocket"));
if (HandSocket)
{
HandSocket->AttachActor(EquippedWeapon, Character->GetMesh());//attaching weapon to a socket
}
}
}