# Having weapons use specific ammo type?

**URL:** <https://forums.unrealengine.com/t/having-weapons-use-specific-ammo-type/345901>\
**Category:** Community & Industry Discussion\
**Tags:** weapon, type, unreal-engine, global, question\
**Created:** [January 30, 2016, 11:19pm UTC](https://forums.unrealengine.com/t/having-weapons-use-specific-ammo-type/345901 "2016-01-30T23:19:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shirk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shirk](https://forums.unrealengine.com/u/Shirk)\
**Post date:** [January 30, 2016, 11:19pm UTC](https://forums.unrealengine.com/t/having-weapons-use-specific-ammo-type/345901/1 "2016-01-30T23:19:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_86d41c48](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_86d41c48](https://forums.unrealengine.com/u/anonymous_user_86d41c48)\
**Post date:** [January 31, 2016, 2:55am UTC](https://forums.unrealengine.com/t/having-weapons-use-specific-ammo-type/345901/2 "2016-01-31T02:55:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Shirk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shirk](https://forums.unrealengine.com/u/Shirk)\
**Post date:** [January 31, 2016, 6:49pm UTC](https://forums.unrealengine.com/t/having-weapons-use-specific-ammo-type/345901/3 "2016-01-31T18:49:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_57b35dc4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_57b35dc4](https://forums.unrealengine.com/u/anonymous_user_57b35dc4)\
**Post date:** [January 29, 2018, 12:20pm UTC](https://forums.unrealengine.com/t/having-weapons-use-specific-ammo-type/345901/4 "2018-01-29T12:20:15Z")

</div>

I need help with this also!

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

---

<div class="post-metadata">

**Author:** ![ThompsonN13](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ThompsonN13](https://forums.unrealengine.com/u/ThompsonN13)\
**Post date:** [January 29, 2018, 4:10pm UTC](https://forums.unrealengine.com/t/having-weapons-use-specific-ammo-type/345901/5 "2018-01-29T16:10:57Z")

</div>

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.

 ![228812-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/1/f/b1fe3ed93c841a9c1d0128fbcc118b0aab453da8.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_57b35dc4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_57b35dc4](https://forums.unrealengine.com/u/anonymous_user_57b35dc4)\
**Post date:** [January 30, 2018, 5:08am UTC](https://forums.unrealengine.com/t/having-weapons-use-specific-ammo-type/345901/6 "2018-01-30T05:08:27Z")

</div>

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?
