Getting the Specific Player Weapon

I’m currently following this tutorial: Displaying Health, Energy and Ammo but I’m having trouble on #10. I’ve got a BP_BaseWeapon that has all my pertinent variables for weapons stored in it, such as weight, magazine ammo, reload time etc. From this BP_BaseWeapon I’ve created specific instances of weapons such as BP_M1Garand which overrides the default values of BP_BaseWeapon.

Obviously I also have a player character, which I’ve added a variable Health to. The character doesn’t need to know the specifics of the weapons so that’s why I separated weapon variables to a generic weapon blueprint to inherit from. So in that tutorial, my character doesn’t have any way to keep track of the weapon, or amount of ammo in order to update the UI. That’s the job of the weapon BP.

Now what I want to do is to get data from the specific, inherited blueprint of the currently equipped weapon. So say the player is using the M1Garand, what would I need to do to have something like a Get Player Weapon function? Does my player character need a variable of BP_BaseWeapon?

Need screenshots of the blueprint code that isn’t working and some of the surrounding code to provide clear context and understanding of what is not working properly.

First I’ll attach the FirstPersonCharacter

118950-firstpersoncharacter.png

And then the two weapon blueprints (BP_BaseWeapon, and in this case BP_M1Garand)

Visually, my problem is this.

118952-problem.png

The player, or FirstPersonCharacter, doesn’t have any way to communicate with the equipped weapon whether that’s the Garand or Thompson or whatever. And I’m not wanting the FirstPersonCharacter to store the information which I have shown in the second image; its more the responsibility of the weapon than the character. Sorry if I’m not wording this well, I know I need some variable in the FirstPersonCharacter to represent what specific instance of BP_BaseWeapon I have but I’m not sure if that would be a variable of type BP_BaseWeapon or what.

You would use a variable of type BP_BaseWeapon. That will allow you to access the equipped weapon’s variables (currentAmmoInMag, etc.)

That makes sense, but would you also have to add something to BP_BaseWeapon to signify which one is currently equipped? Or in FirstPersonCharacter, BP_BaseWeapon is the same variable type which holds all the information you need, but how would you access them? Would it be setting you equipped weapon var to be the get ___ of BP_BaseWeapon?

When you instantiate a M1Garand or Thompson they both inherit from BP_BaseWeapon, so in your FirstPersonCharacter or PlayerController (which ever you choose) you can create a variable named BP_BaseWeapon of type BP_BaseWeapon (like Slart5150 mentioned).

In the world, when your M1Garand or Thompson guns are spawned and then assigned to the FirstPersonCharacter you just need to cast the spawn instance to a BP_BaseWeapon and then store it in the class variable.

After casting an instance of M1Garand to BP_BaseWeapon you will still be able to identify if the object is an instance of M1Garand (after casting, that information is still retained for the object instance).

Thank you for your help! I was able to get it working