Weapon Swapping?

I’ve searched throughout the internet and the forums but all I found was switching between a weapon you have and one on the ground.
Basically I’d like to know how can I switch between 2 or more weapons I already own, simply by clicking 1 or 2, or scrolling the mouse.
So for example, I spawn with a pistol, and when I click 2, assuming I have the weapon, I switch to a shotgun.

this is Basic programming :

Have a variable as an index.
By pressing 2 or 3 you Change this variable to 2 or 3.
You can then Change your weapon accordingly to this variable.

We don’t have your Code so we can’t know what you already have and what not.

What I’m wondering is how I do the switch, if I just do an animation or have the weapons already attached to the player.

I’m also using blueprints, not code.

You should do an Animation Montage that lets the Player put away the gun and pull out the weapon.
You Need to use Anim Notifies to Switch Meshes.

I’ve been looking around and found this by another user: 4e1c90380c127602cfab8caf1a4b68eac47f7cc3.png

That seems simple though I’m confused on I do I set up the function, I got the Graph with the Byte input added but I don’t know specifically on what I should link to.

So I’ve been trying to find a solution to this, I’ve managed to replicate the image above in how I want it, but it’s obviously not working, I think because I haven’t associated the enums with the actual weapons, any suggestions?




This is a good starting Point.
drag off the enum pin and create “Switch over” node. You may want to Play different Animations for each weapon and also Exchange the Weapon Model in the Hand.

If you’re talking about the “Weapon” node in the second image, when I drag it over and type “switch over” these two appear: “Switch on EOverlapFilterOption” and “Switch on ESimulationOverlap”.

You did create an Enum for this, didn’t you?

Search for “Switch over ENUM” where ENUM is your custom Enum.

You can see the Enum in the 3rd picture.


oh, my bad.
It’s Switch ON. :o


I’m guessing now I have to connect these two to their respective weapons? Do I connect to the static mesh/skeleton?

These Execution Paths (Pistol and Shotgun) now Need their own logic for switching.
Play an Animation that first puts the current weapon away and then Play the Animation that pulls out the desired weapon.
Change the current selected Weapon , Swap Meshes etc.

So I’ve made some progress, but it’s still not how I want it.

On the topic of animations, I don’t really want those right now, I just want it to change immediately, no animation for it.

Here’s the main function: EzPWloS.png

Here’s the Event Graph: K3c3LYE.png

Now, if I start my character with just his hands (no weapon on it), and I press 1, the Pistol does show up, but if I press 2 the Shotgun doesn’t.

There’s one problem though, whenever I press one of the numbers, it adds one more weapon in front of me, so they overlap each other, I can have like 12 more items and they don’t kill themselves after I press another button (so if I had a pistol and pressed 2 for shotgun, I’d want it to kill the pistol and summon the shotgun).

I suspect the shotgun doesn’t appear because I don’t have it in the skeleton like I have with the pistol, here’s the error that shows up: vtaJQm1.jpg

So, basically:

How do I kill the pistol when I switch to the shotgun and vice-versa?

How do I implement the shotgun in the same place as the pistol is?

You only ever want to spawn each weapon one time and create a reference to each of those weapons . Then for weapon switching you simply hide one mesh and show the other .

So for example . You want pistol and shotgun . So first go into character and on the hand bone . Make two sockets that will be the spawn position of the different guns . Use a preview asset to position them accordingly and line them up .

Next in you’re character make a function called spawn weapons .
Spawn each weapon and set its position to be the newly created socket positions . Drag off from the spawn node and set these in a variable which will be a reference to that particular gun . This is useful because you can use it over and over again whenever you want to do something with that gun .

Then make an enum . Shotgun , pistol

Switch on enum when you press 2 hide pistol mesh , show shotgun mesh , when you press 1 hide shotgun mesh show pistol mesh

You have to think of a data structure for weapons that stores the weapon mesh so you can easily exchange the meshes.

How about a scroll wheel weapon array? Store all the meshes in a array and just swap them as needed. Scroll input +1 or -1, add the axis value to the index. If the index is less than 0 then set the index to the array length or if the index is greater than the array length set the index to 0, otherwise set the mesh to the index.


Thanks btw, I’ve replicated your image there, but when I start the game, now my pistol doesn’t even appear, and scrolling the wheel doesn’t do anything, here are some images to state what I’m saying.



When I fire, I also get an error.


You missed a link.


See if that works, if not check that the array is populated. Add a print string with the string set to the scroll wheel value to make sure its firing properly. I’m not sure why your set skeletal mesh function doesn’t have the reinit pose bool, this may be the reason for the error.

I’ve fixed the missing link but there’s no “Set Skeletal Mesh” with the Reinit Pose Bool, might be because of the UE version? I’m the .11 version.