How Do I Change Weapon Mesh

Hi,

I’m attempting to create a simple press 1 - 4 to change weapon system. I’m working from the C++ first person template. I have created a method that is called whenever the player presses 1. I don’t know how to proceed to write the method.

I want the ammunition in the current magazine to be kept the same whenever the player switches to different weapons.

I have read that destroying the current mesh and then making a new one with a different weapon is possible, also hiding different weapon meshes and only showing one at a time. How would I go about doing this?

This is the template code in the character class that has to do with the weapon:

// Create a gun mesh component

FP_Gun = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("FP_Gun")); 
FP_Gun->SetOnlyOwnerSee(true);			// only the owning player will see this mesh
FP_Gun->bCastDynamicShadow = false;
FP_Gun->CastShadow = false;
// FP_Gun->SetupAttachment(Mesh1P, TEXT("GripPoint"));
FP_Gun->SetupAttachment(RootComponent);

FP_MuzzleLocation = CreateDefaultSubobject<USceneComponent>(TEXT("MuzzleLocation"));
FP_MuzzleLocation->SetupAttachment(FP_Gun);
FP_MuzzleLocation->SetRelativeLocation(FVector(0.2f, 48.4f, -10.6f));

And then in the begin play method:

FP_Gun->AttachToComponent(Mesh1P, FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true), TEXT("GripPoint"));

NW: I have tried changing the line FP_Gun = CreateDefaultSubobject(TEXT(“FP_Gun”)); from “FP_Gun” to “MyAssaultRifle” and then changing the static mesh thats on the in scenecharacter to MyAssaultRifle, this causes the program to crash when I hit play. Is there something else that I should also be changing? The character blueprint looks like this and has no space to input a static mesh for the Fp Gun for some reason:

To answer the question directly, You could make something like this:

UFUNCTION(BlueprintCallable)
void SwapMesh(USkeletalMesh* toChange)
{
    FP_Gun->SetSkeletalMesh(toChange);
}

But if it were me, I’d make a new weapon class and spawn in / destroy the weapons on button press. That way you can have each one handle a fire event in its own way (Sound, particles, bullet type). The ammunition amounts can be stored on your pawn.