I am watching a tutorial series. I watch a few videos then play around with what I learned. During the tutorial we added a weapon to the character by spawning the weapon then attaching it to the characters hand socket. Previously we added a barrel socket to the characters current gun that came attached to the mesh. I am using a different weapon asset. Now I am having a hard time getting access to that meshes socket. I managed to get it, but the socket is at my characters feet while the weapon is in the characters hand. Iām sure its hard to make out what I am talking about. My code to get the socket of the attached weapon is posted. Any advice on what I am doing wrong is greatly appreciated.
if (EquippedWeapon)
{
const USkeletalMeshComponent* WeaponMesh = EquippedWeapon->GetPickupMesh();
const USkeletalMeshSocket* BarrelSocket = WeaponMesh->GetSocketByName("BarrelSocket");
if (BarrelSocket)
{
const FTransform SocketTransform = BarrelSocket->GetSocketTransform(GetMesh());
if (MuzzleFlash)
{
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), MuzzleFlash, SocketTransform);
}
FVector BeamEnd;
bool bBeamEnd = GetBeamEndLocation(SocketTransform.GetLocation(), BeamEnd);
if (bBeamEnd)
{
if (ImpactParticles)
{
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactParticles, BeamEnd);
}
UParticleSystemComponent* Beam = UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), BeamParticles, SocketTransform);
if (Beam)
{
Beam->SetVectorParameter(FName("Target"), BeamEnd);
}
}
}
}