Inventory equip and unequip problem

Hello there. I’m at my wits end with my equipping/unequipping system in Unreal. I’m fairly new to UE4 in terms of actually making progress on a project but I have a basic grasp on most things. The problem I am having is when I drop a different item that is in the same class as an item I have equipped. So I have an axe in my hand and a pistol in my inventory that are both in the same “Equippable” class of my inventory item struct and dropping the pistol from my inventory causes the axe to become unequipped. I know why but cant figure out a way around it due to my lack of knowledge, that’s where i’m hoping you, the experts, come in. I am fairly certain that its all down to the fact that the weapons are in the same class so when im dropping the item and it unequips, its not able to differentiate between the 2 items. I’m essentially looking for a way to make these 2 (2 so far, im planning more) items separate. I really hope this makes sense. Ill post screenshots of my dropping system, Equip, Unequip blueprints and such.

Its probably worth mentioning that i have no character mesh so am using a spring arm with a child actor component attached that i change depending on the item i equip. If you need more information, ask away.

Thanks for taking the time and please go easy with the guidance since im not incredibly experienced.

The_tubby1,

My inventory system is a little different than yours but maybe this might help.

First I would store the name of the equipped items inside a variable string or string array (multiple items equipped for instance).

Then when I drop an item I would grab the name of this item and have a check that would match the array items or variable string with the item display name being dropped and if they don’t match then drop it and leave the other one there.

Hope this helps

This sounds like something I may need to do. Thanks for a quick reply! :smiley:

Ok. this is killing me. I attempted something along the lines of what you said but I’m just not getting anywhere. Don’t suppose you could elaborate a little?

In your first image where you break the item structure down, that is where I would grab the name of the item and store it in the equipped string or array.

In your second image where you remove the index you would first create a check using the display name of the item or a custom tag, to make sure the index being removed from your inventory does not match the items that are equipped (stored inside that string/array).

if you still cannot get it check out this video set on making an inventory system in UE4…

This is what I used but I expanded on it greatly and it works for everything I need. The video is a little dated but it works.

This also seems correct but I’m not quite sure how to apply it.

everything should be based on your equipment array of integers, referring to elements in your inventory array of items.

inside the character blueprint, which has your inventory array, add a new variable. make it an array of integers, call it Equipment.

the first element of this Equipment array can represent the item held in your right hand socket. the next element can be the left hand socket, the Nth element can be rings or hats or boots or whatever other wearable item slots you want. or the first 10 elements can represent a hotbar in a game like Minecraft, or they can represent custom button configurations in the options menu, etc…

equipment usually works like this: you select which equipment slot you are equipping, which brings up a list of relevant items from your inventory, then you select an item to equip to that slot, which brings you back to the first menu with a changed selection.

so you have SlotIndex from the first menu, and InventoryIndex from the second menu, and you set the Character’s Equipment[SlotIndex]to the value of InventoryIndex, then you can change any skeletal meshes or child actors, or any other visual equipping effect…

but everything should be based on your equipment array of integers, referring to elements in your inventory array of items.

Ok, so far I have created the array in my character blueprint and have this for the equip event -

This is showing me that it knows what Item ID it is equipping which in itself is progress. However, the problem still lies in unequipping. A print string i have setup for that, always returns with “0” as the ID of the item i drop. Im definitely doing something wrong. here is the unequip and drop part. -

I understand what you mean and get it in theory, i just dont know the right way to do it.

EquipItem, and UnequipItem functions should have an integer input that represents which slot you are equipping. use that to know which Equipment index you are changing.

dropping an item is a separate function from unequipping, but when you drop an item, for each integer in Equipment array, you can compare that integer with the inventoryButtonClicked integer. if they are equal, unequip.

Does it need to be an array if I only have the one slot to equip items to? (The hand).

i recommend using an array, so it works for the general case. when you drop an item, an array allows you to easily iterate over all equipped items, to see if they are being dropped, using a for-each loop.

if you used separate variables, instead of an array, every time you wanted to add a new equipment slot, you would have to change other parts of the code to know how to communicate with the new variable, which would make your code high maintenance.

to keep code low maintenance, its good to generalize problems and solve them from the perspective that you will probably need more than one of these things, so design it as an array.

That makes sense. I will keep working at it but I still cant get past it. its just that I don’t know exactly how to structure everything and what to put where and in what order. It’s a giant pain in the butt.