Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How Do I Change Weapon Mesh


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_MuzzleLocation = CreateDefaultSubobject<USceneComponent>(TEXT("MuzzleLocation"));
 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"));
Product Version: UE 4.22
more ▼

asked Apr 09 '19 at 02:14 AM in C++ Programming

avatar image

3 1 2

avatar image Nuthead Apr 09 '19 at 03:41 PM

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: alt text

screenshot-1.png (215.8 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

 void SwapMesh(USkeletalMesh* 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.

more ▼

answered Apr 10 '19 at 04:01 PM

avatar image

61 5 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question