Help with structure

I am working on a project in where it’s possible to get 6 weapons, and only 6 weapons (one of each weapon), and each weapon goes into a specific ‘slot’ on the player. Once the player picks up a weapon, they can switch to the weapon using numpads 1-6.

The problem I am having, is trying to store the ‘slot data’ on the character blueprint. Each bp_weaponname is a child of bp_weapon, which has a ‘weaponData structure’ on it, which stores the slot # the weapon goes in, the weapon name, and whether the player has the weapon or not.

All of that works great, and the keybinds for switching weapons etc are in place (I am only using prints right now until I figure out the slot stuff), and I can interact with weapons to pick them up (but storing them doesn’t work, for obvious reasons).

I am trying to figure out how I can store slot information on the player blueprint, and store the weapon pawn in the correct slot when it’s picked up. I tried creating an ‘equippedWeapons’ structure attached to the player character (with slots1-6 defined as bp_weaponname etc), but I can’t set a default value in the editor (I receive a ‘Editing this value in a Class Default Object is not allowed’ error).

Am I going the correct route for doing this? Ideally, there is a variable with slots 1-6 (and possibly more later if we add more guns) stored on the player blueprint, and whenever a gun is interacted with, it executes a function to store the picked up weapon in the correct slot on the player.

Any help would be greatly appreciated. I thought a struct is what I needed to do this, but that doesn’t appear to be the case.

Sorry if this post is confusing. I wanted to outline the intended functionality. Everything except for the slot variable on the player, and the function to set a weapon into one of those slots, is working. I just am having trouble figuring out how to store the needed data on the player.

Wow, I feel stupid as ever. Yeah, you’re right. I ended up adding a ‘weapons’ variable of type ‘structure’ on the player, and next to the variable declaration there’s a little ‘type’ icon to change from single value to array, etc.

Now when I pick up an item, I cast to the playercharacter, and using the bp_weaponname ‘slot’ integer value on the structure for the array index, I add the bp_weaponname to the ‘weapons’ array on the playercharacter.

Sounds like it’s going to go wrong.

Why not just actually put the weapons ‘in slots’?

You could have an array of weapons on the player, if there’s a weapon in a given slot, then you know it’s there, no need to store which slot it’s in.

The weapon is the place to hold all the info on each weapon’s status ( ammo etc ).

To do this smoothly, you need to take a look at blueprint inheritance. You’ll need a weapon parent, and the various types of weapons will be children of that:

PS: Also, if you use an array, you also don't need a bool to say if the player has the weapon or not, because they will actually have it...

@clockworkocean storing the ‘slot’ on the player is what I am trying to do. I have all the weapon information already stored on the weapon children, I just cant figure out how to build the slot data structure on the player. Im used to working with typical key/value arrays which I can’t seem to find in blueprints.

It’s just an array of structures. The array variable lives in the player.

Thanks to @ClockWorkOcean for helping me through this. I was going about it all wrong.

I ended up saving an array variable of bp_weapon structure to the ‘ThirdPersonController’ blueprint.

Now, whenever I pick up a weapon, I use the ‘slot data’ and ‘self’ reference of the weapon I picked up and cast to the ‘ThirdPersonController’ and ‘set’ the array index (slot data from the weapon) of the ‘weapons’ array to the self reference of the weapon I picked up.