Should i have WeaponBase Actor

I making FPS game and i have 2 place holders one for pistol other rifle, and both of them are in character class (i wont adding hands to project). So i dont know should i put weapon in sperate actor or go with already made system. Player will be able to hold 2 weapons max.

Hey @Player_003,
Depends on how in-depth you want to go, really! If you’re looking for expansive functionality and control, creating your own system would be a good route to take. If you’re looking for more simplistic functionality and quicker development time, you could go with a pre-made weapons system.
I’d personally recommend splitting them up, just because it makes the de-bugging process a bit easier, and helps the code be a bit more readable.
I hope this can help you out!
-Zen

My personal preference is a single parent weapon class. Have all the firing, reload, recoil etc logic in this one class. Then create a child class for Pistol and one for Rifle.

Weapons (Parent, Actor)
– Wep_Pistol (child of Weapons)
– Wep_Rifle (child of Weapons)

From here you’d simply create children for the individual weapons.

Wep_Pistol → Pistol_Colt1911, Pistol_Beretta92, Pistol_Glock39…
Wep_Rifle → Rifle_M416, Rifle_AK47, Rifle_M16A4…

If you decide to expand on the types to have more variation such as SMG, AR, SR, DMR, Shotgun, PDW. In the parent class (Weapons) create an enum for identification. Then create a child for each type… set the enum in the child.

Weapons
– Wep_PDW → PDW_Colt1911, PDW_Beretta92 …
– Wep_AR → AR_M416, AR_AK47 …
– Wep_SMG → SMG_UMP45, SMG_MAC11 …

This method simplifies debugging drastically. 99% of the logic is in the Parent class. Children can have soft modifications (Wep_PDW, Wep_AR). Specific weapons are simply configurable classes. Nothing to code.

i pose this more as a question than an answer because it is only something i’ve done a couple times but… sometimes i dont even need a child class. Like if the only thing a child class does is change the static mesh and some variables, I just might have a single “Weapon” class and it gets all info about a weapon type from data table (including what mesh to use).

Then when an instance of the class if created you can just pass in a name or some form of ID that can be used to lookup in the data table and get things setup.

I dunno if this is a good idea for many situations but i’ve done it in simple single player games and it works fine - pretty simple overall to manage.

For the most part this is what I do with the class type children. Data tables for the win.

For beginners I find it easier for them to learn class inheritance with the drawn out method I posted. Once they get a solid grasp it’s just a little work to back track a tad and add DT support.

1 Like