Switching weapons system

Hello everyone.
I’m here to ask about a problem that is keeping me awake. I’m talking about a system that allows the player to switch between equipped weapon, maintaining the gun characteristics and related animation. I’m completly new on this type of dveloping but now youtube and google haven’t helped me at all.
Can you guys explain me briefly the basic of the system and maybe attach a simple blueprint ? (I will give more infos or adapt the example to my project)

Hey there @Masterthecaster2! Welcome to the community! So depending on which part of the system you need help with, I’ve got different resources and I’ll also explain from a high level how you could go about some of these things.

Depending on how you intend your weapon system to be set up, there’s a million ways of handling this. I’ll go over how I’d set it up from a high level perspective with a couple of good practices (and bad ones) sprinkled in. So for example, maybe you are making a shooter and you want different equip animations, reload animations, shot animations etc.

You’re going to immediately realize you will have to code a shoot function for all of them, a reload, a melee, and a swap as well as animate all of these. To cut down on work (and also try to remain object oriented) we’re going to use 2 principals called polymorphism and inheritance.

The first tutorial linked goes over (very very lightly) how to make a base class and then have all the child classes inherit from it. This will allow you to make singular logic for firing, reloading, melee, etc. on the base class and only override it on the child class when needed.

Then, once you write the logic for you weapons, you’d move on to tutorial 2 where you can start to see how the animation is at play. For simple first person games, having a montage that you trigger in BP would work fine, though if you want cohesiveness with the character you’ll need to work with the animBP as shown there. This can be set up the same or different from your weapons, the only way to differentiate would be to poll which weapon you have in your hand or have the weapons call back to the player for that (bad practice but quick and easy).

From there you’ll have to frankenstein your system together with that design (or go crazy, it’s however you want it). Good luck!

Resources

Weapon swapping tutorial:

Weapon swapping + Animation:

1 Like