diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp index dde8cb8c..891eabc8 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp @@ -257,13 +257,20 @@ void ABaseWeaponClass::InteractPrompt() void ABaseWeaponClass::SetupSilencerAttachment(UStaticMesh* SilencerMesh) { + GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("SETTING UP SILENCER ATTACHMENTS")); FTransform emptytransform; UActorComponent* SilencerComponent = AddComponentByClass(USilencerAttachmentClass::StaticClass(), true, emptytransform, false); - Cast(SilencerComponent)->AttachToComponent(RootComponent, FAttachmentTransformRules::SnapToTargetIncludingScale); - TArray SilencerMeshSocketArray (GetComponentsByTag(UStaticMeshComponent::StaticClass(), FName("SilencerMeshSocket"))); - Cast(SilencerMeshSocketArray[0])->SetStaticMesh(SilencerMesh); + UStaticMeshComponent* SilencerMeshComponent = Cast(AddComponentByClass(UStaticMeshComponent::StaticClass(), true, emptytransform, false)); + SilencerMeshComponent->SetStaticMesh(SilencerMesh); + SilencerMeshComponent->AttachToComponent(Cast(GetComponentByClass(USkeletalMeshComponent::StaticClass())), FAttachmentTransformRules::SnapToTargetIncludingScale, FName(TEXT("SilencerMeshSocket"))); + Cast(SilencerComponent)->AttachToComponent(SilencerMeshComponent, FAttachmentTransformRules::SnapToTargetIncludingScale); + FTransform SilencerSocketTransform = SilencerMeshComponent->GetSocketTransform(FName(TEXT("SilencerMeshSocket")), RTS_Component); + FRotator SilencerSocketRotation = SilencerMeshComponent->GetSocketRotation(FName(TEXT("SilencerMeshSocket"))); + SilencerMeshComponent->SetRelativeTransform(SilencerSocketTransform); + SilencerMeshComponent->SetRelativeRotation(this->GetActorRotation()); + } - + \ No newline at end of file