From e3af853bdd69ac672e521535f3b42c5a574f7acb Mon Sep 17 00:00:00 2001 From: MARCEL HARA Date: Fri, 26 Jan 2024 18:35:44 +0000 Subject: [PATCH] Re-Worked Workbench code to use sockets instead of mesh loc --- .../WeaponSystem/BaseWeaponClass.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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