Created ExtendedMag attachment code to baseweapon class

This commit is contained in:
MH261677 2024-03-19 13:12:37 +00:00
parent 1cf66a7773
commit e2eb32653e
4 changed files with 82 additions and 6 deletions

View File

@ -278,6 +278,7 @@ void ABaseWeaponClass::InteractPrompt()
WeaponStatsPopUp();
}
//Called in weaponworkbench WBP
void ABaseWeaponClass::SetupSilencerAttachment(UStaticMesh* SilencerMesh)
{
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("SETTING UP SILENCER ATTACHMENTS"));
@ -290,11 +291,13 @@ void ABaseWeaponClass::SetupSilencerAttachment(UStaticMesh* SilencerMesh)
{
if (IsValid(WeaponSkeletonMesh))
{
//this handles giving the weapon the required component class/code
SilencerAttachmentClass->AttachToComponent(WeaponSkeletonMesh, FAttachmentTransformRules::SnapToTargetIncludingScale, FName(TEXT("SilencerMeshSocket")));
UE_LOG(LogTemp, Display, TEXT("All Attachment is valid"));
//this makes it showup in editor for better debugging
SilencerAttachmentClass->CreationMethod = EComponentCreationMethod::Instance;
SilencerAttachmentClass->RegisterComponent();
//below handles seeing the physical attachment you selected
UStaticMeshComponent* StaticMeshComp = NewObject<UStaticMeshComponent>(SilencerAttachmentClass, UStaticMeshComponent::StaticClass());
if (IsValid(StaticMeshComp))
{
@ -309,3 +312,44 @@ void ABaseWeaponClass::SetupSilencerAttachment(UStaticMesh* SilencerMesh)
}
}
}
//Called in weaponworkbench WBP
void ABaseWeaponClass::SetupExtendedMagAttachment(UStaticMesh* ExtendedMagMesh)
{
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, TEXT("SETTING UP EXTENDEDMAG ATTACHMENTS"));
FTransform EmptyTransform;
USceneComponent* ExtendedMagAttachmentClass = Cast<USceneComponent>(AddComponentByClass(USilencerAttachmentClass::StaticClass(), false, EmptyTransform, false));
ExtendedMagAttachmentClass->ComponentTags.Add(FName("AttachmentType"));
USkeletalMeshComponent* WeaponSkeletonMesh = FindComponentByClass<USkeletalMeshComponent>();
if (IsValid(ExtendedMagAttachmentClass))
{
if (IsValid(WeaponSkeletonMesh))
{
//this handles giving the weapon the required component class/code
ExtendedMagAttachmentClass->AttachToComponent(WeaponSkeletonMesh, FAttachmentTransformRules::SnapToTargetIncludingScale, FName(TEXT("SilencerMeshSocket")));
UE_LOG(LogTemp, Display, TEXT("All Attachment is valid"));
//this makes it showup in editor for better debugging
ExtendedMagAttachmentClass->CreationMethod = EComponentCreationMethod::Instance;
ExtendedMagAttachmentClass->RegisterComponent();
//below handles seeing the physical attachment you selected
UStaticMeshComponent* StaticMeshComp = NewObject<UStaticMeshComponent>(ExtendedMagAttachmentClass, UStaticMeshComponent::StaticClass());
if (IsValid(StaticMeshComp))
{
StaticMeshComp->AttachToComponent(ExtendedMagAttachmentClass, FAttachmentTransformRules::SnapToTargetIncludingScale);
StaticMeshComp->SetStaticMesh(ExtendedMagMesh);
StaticMeshComp->SetRelativeRotation(FRotator(0, 90, 0));
StaticMeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
//Making it show in editor for debugging
StaticMeshComp->CreationMethod = EComponentCreationMethod::Instance;
StaticMeshComp->RegisterComponent();
}
}
}
}
//Called in weaponworkbench WBP
void ABaseWeaponClass::SetupGripAttachment(UStaticMesh* GripMesh)
{
}

View File

@ -175,6 +175,12 @@ public:
UFUNCTION(BlueprintCallable)
void SetupSilencerAttachment(UStaticMesh* SilencerMesh);
UFUNCTION(BlueprintCallable)
void SetupExtendedMagAttachment(UStaticMesh* ExtendedMagMesh);
UFUNCTION(BlueprintCallable)
void SetupGripAttachment(UStaticMesh* GripMesh);
UFUNCTION(BlueprintImplementableEvent)
void ShowReloadingWidget();

View File

@ -1,11 +1,11 @@
$COPYRIGHT_LINE$
// Fill out your copyright notice in the Description page of Project Settings.
$MY_HEADER_INCLUDE_DIRECTIVE$
#include "ExtendedMagAttachmentClass.h"
// Sets default values for this component's properties
$PREFIX$$UNPREFIXED_CLASS_NAME$::$PREFIX$$UNPREFIXED_CLASS_NAME$()
UExtendedMagAttachmentClass::UExtendedMagAttachmentClass()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
@ -16,17 +16,17 @@ $PREFIX$$UNPREFIXED_CLASS_NAME$::$PREFIX$$UNPREFIXED_CLASS_NAME$()
// Called when the game starts
void $PREFIX$$UNPREFIXED_CLASS_NAME$::BeginPlay()
void UExtendedMagAttachmentClass::BeginPlay()
{
Super::BeginPlay();
// ...
$END$
}
// Called every frame
void $PREFIX$$UNPREFIXED_CLASS_NAME$::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
void UExtendedMagAttachmentClass::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

View File

@ -0,0 +1,26 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/SceneComponent.h"
#include "ExtendedMagAttachmentClass.generated.h"
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class ENDLESSVENDETTA_API UExtendedMagAttachmentClass : public USceneComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UExtendedMagAttachmentClass();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};