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.
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.
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?