Added grip attachment code to baseweaponclass

This commit is contained in:
MH261677 2024-03-20 16:07:59 +00:00
parent df8fccfe57
commit 2e6d88a53f
2 changed files with 31 additions and 3 deletions

View File

@ -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<USceneComponent>(AddComponentByClass(UGripAttachmentClass::StaticClass(), false, EmptyTransform, false));
GripAttachmentClass->ComponentTags.Add(FName("AttachmentType"));
USkeletalMeshComponent* WeaponSkeletonMesh = FindComponentByClass<USkeletalMeshComponent>();
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<UStaticMeshComponent>(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()

View File

@ -29,7 +29,5 @@ void UGripAttachmentClass::BeginPlay()
void UGripAttachmentClass::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}