Having weapons use specific ammo type?

Ive set up a parent blueprint that all my weapon blueprints inherit from, and within each weapon blueprint there is a variable TotalAmmo that defines the total ammo available to that weapon. I would like to know how to set up so that weapon uses a specific ammo type like Rifle, Pistol, Shotgun, ect and how to store that value so all similar guns can access and use it too, so when I shoot and the TotalAmmo gets reduced by one, all weapons using the ammo will also have 1 less bullet.

How might I go about doing this?

Create an Enum called ammotype, and add all the ammotypes you’ll need.

Then in your parent gun class create the ammotype enum, and set it in each of your child’s classes.

You should be able to do all the math you need with that.

Thats exactly what I have at the moment, except the enum is in a struct. Could you explain to me basics of the math behind it?

I need help with this also!

I know the post is old but can someone pls elaborate on this topic.

it really depends on how you are looking to implement this. the easiest way to do it i would imagine is to have several variables for your your ammo on the player ( i will use the third person character here). so create pistolAmmo, rifleAmmo, and shotgunAmmo variables on the character. then in your weapon blueprint cast to your characterclass and drag off its output pin and search “get pistolAmmo”. this will get you a reference to the variable in your characterBP. repeat the process for the rest of the variables. now when you fire your weapon get the variable of the ammo type you wish to use then decrement it and set it. so something like: Fire input → cast to character → get RifleAmmo → RifleAmmo -1 → Set RifleAmmo.

Here is my scenario that I am trying to do.

ATM: Ammo is stored on BP_BaseWeapon

Wanting: Ammo to be stored on character, BP_BaseWeapon then uses ammo from character and then tell character that you’ve just used the ammo…

But here’s the problem…Pistol, Rifle and Shotgun are all child classes of BP_BaseWeapon.

BP_BaseWeapon has variables:
CurrentAmmo (120)
CurrentAmmoInMag (30)
AmmoPerMag
MaxAmmo (120)
AmmoConsumedPerShot (1)

IF i make BP_PlayerCharacter have the variables CurrentAmmo, CurrentAmmoInMag…etc. Then the pistol will be using the same variable values as my rifle is. So if i spawned with a rifle and pistol, both the rifle and pistol would have 120 CurrentAmmo and also both would have 30 CurrentAmmoInMag. If i fire with my rifle it also takes ammo off of my pistol.

How would I make it so that if I fire my rifle it only uses ammo of the rifle. Also if i was to drop that rifle and pick up a new rifle, how do i tell the new rifle to reset the amount of ammo i have to the amount that the new gun has. OR if I drop 1 rifle, pick a new one up and then drop the 2nd rifle and pick the old one up again, how do i tell the character how much ammo that rifle had?