From 2e6d88a53ffc0386481f769da530922511abf62f Mon Sep 17 00:00:00 2001 From: MH261677 Date: Wed, 20 Mar 2024 16:07:59 +0000 Subject: [PATCH] Added grip attachment code to baseweaponclass --- .../WeaponSystem/BaseWeaponClass.cpp | 32 ++++++++++++++++++- .../GripAttachmentClass.cpp | 2 -- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp index 1845d1c8..e871a7b4 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp @@ -14,6 +14,7 @@ #include "EndlessVendetta/BountySystem/ControlsTraining/TargetDummy.h" #include "EndlessVendetta/Workbench&Attachments/ExtendedMagAttachmentClass.h" +#include "EndlessVendetta/Workbench&Attachments/GripAttachmentClass.h" #include "EndlessVendetta/Workbench&Attachments/SilencerAttachmentClass.h" @@ -352,7 +353,36 @@ void ABaseWeaponClass::SetupExtendedMagAttachment(UStaticMesh* ExtendedMagMesh) //Called in weaponworkbench WBP void ABaseWeaponClass::SetupGripAttachment(UStaticMesh* GripMesh) { - + GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("SETTING UP GRIP ATTACHMENTS")); + FTransform EmptyTransform; + + USceneComponent* GripAttachmentClass = Cast(AddComponentByClass(UGripAttachmentClass::StaticClass(), false, EmptyTransform, false)); + GripAttachmentClass->ComponentTags.Add(FName("AttachmentType")); + USkeletalMeshComponent* WeaponSkeletonMesh = FindComponentByClass(); + if (IsValid(GripAttachmentClass)) + { + if (IsValid(WeaponSkeletonMesh)) + { + //this handles giving the weapon the required component class/code + GripAttachmentClass->AttachToComponent(WeaponSkeletonMesh, FAttachmentTransformRules::SnapToTargetIncludingScale, FName(TEXT("GripMeshSocket"))); + UE_LOG(LogTemp, Display, TEXT("All Attachment is valid")); + //this makes it showup in editor for better debugging + GripAttachmentClass->CreationMethod = EComponentCreationMethod::Instance; + GripAttachmentClass->RegisterComponent(); + //below handles seeing the physical attachment you selected + UStaticMeshComponent* StaticMeshComp = NewObject(GripAttachmentClass, UStaticMeshComponent::StaticClass()); + if (IsValid(StaticMeshComp)) + { + StaticMeshComp->AttachToComponent(GripAttachmentClass, FAttachmentTransformRules::SnapToTargetIncludingScale); + StaticMeshComp->SetStaticMesh(GripMesh); + StaticMeshComp->SetRelativeRotation(FRotator(0, 0, 0)); + StaticMeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision); + //Making it show in editor for debugging + StaticMeshComp->CreationMethod = EComponentCreationMethod::Instance; + StaticMeshComp->RegisterComponent(); + } + } + } } void ABaseWeaponClass::RemoveAllAttachments() diff --git a/EndlessVendetta/Source/EndlessVendetta/Workbench&Attachments/GripAttachmentClass.cpp b/EndlessVendetta/Source/EndlessVendetta/Workbench&Attachments/GripAttachmentClass.cpp index 79ba4488..cbced9f9 100644 --- a/EndlessVendetta/Source/EndlessVendetta/Workbench&Attachments/GripAttachmentClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/Workbench&Attachments/GripAttachmentClass.cpp @@ -29,7 +29,5 @@ void UGripAttachmentClass::BeginPlay() void UGripAttachmentClass::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - - // ... }