Hey all,
I’ve been trying to get this to work all day with no luck. I want to attach a weapon to my character after he picks it up.
My weapon class has the following constructor:
AWeapon::AWeapon(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
// Create the base collision sphere component and set it as the root
BaseCollisionComponent = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("BaseSphereComponent"));
RootComponent = BaseCollisionComponent;
// Create and configure the mesh for the pick up and attach it to the root
WeaponMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("WeaponMesh"));
WeaponMesh->SetSimulatePhysics(true);
WeaponMesh->AttachTo(RootComponent);
SetReplicates(true);
}
When the character overlaps the weapon I call EquipWeapon in which I’ve tried numerous ways to attach it to the hand of my character, the most recent being:
void AMainCharacter::EquipWeapon(AWeapon* WeaponToEquip)
{
EquippedWeapon = WeaponToEquip;
EquippedWeapon->AttachRootComponentToActor(this, TEXT("WeaponSocket"), EAttachLocation::SnapToTarget);
}
But the weapon just sits there and doesn’t do anything. Does anyone have a working example of how to do this? I’ve tried googling, but all the examples I’ve seen are from people who are having similar problems.