Item doesn't get added to inventory

Hi, I’ve got this set up but nothing gets added to the player inventory, I used print strings to figure out exactly what the issue is, and it’s only with the ‘Adds to inventory if you already have one and the item is stackable’ part. The event goes through all the way to the destroy actor node, but if I pick an item up which I don’t have in my inventory, say a medkit, that gets added fine, then I try and pick another one up, that also works fine, so it’s all going through correctly, then I tested it with the item ‘Assault Rifle Ammo’ and it picked it up fine the first time, then the second time when I had it in my inventory the print string read the item as ‘None’. I figured this was because the name had spaces maybe, so I tried it with the item ‘metal’ and it worked fine just like the medkit, then I tried it with ‘Pistol Ammo’ and exactly the same as Assault Rifle Ammo it came up as ‘None’.

I just tested it again and I picked up 3 ‘Assault Rifle Ammo’, the first was added to my inventory, the next two came back as ‘None’ and didn’t get added, then I went over and picked up 3 ‘Metal’, the first one added as ‘Metal’, but the next two came up as ‘Assault Rifle Ammo’, so I tried it again with Pistol Ammo and Medkits and the same thing happened.

Now I just tested it again and I got 3 of each item without spaces in the name, and every one of them behaved like the ones with spaces were, working for the first one but coming up as ‘None’, so it can’t be the names having spaces being the issue, but it’s definitely an issue with the 'Adds to inventory if you already have one and the item is stackable.

Can anyone help please? I don’t understand what’s happening. Bearing in mind I didn’t edit the code at all between tests.

Also I don’t think the ‘Adds a new copy of an item if you have one already and it’s not stackable’ part works either because Maps can only have one row with that name so it can’t add another one with the same item name, I don’t know how to test that though as I don’t know how to use the map variable for the inventory that’s in the character BP, all of this function is in the lootable item BP, and the inventory display would have to be in a widget, so I don’t know how to add all the items from the Map variable to the visible inventory.

Edit: I’ve added a video showing what’s happening, pay attention to the print strings, the quantity in the inventories and what’s happening to the items when you pick them up.

Edit 2: I forgot to link the video, my bad Inventory Help - YouTube

Every time I test it it seems to behave differently, that time I started by picking up 3 lockpicks, each one worked, then I tried picking up medkits (I set the default in the inventory to 2) and it returned as ‘None’, then I picked up 3 ‘Metal’ and 3 ‘Alcahol’ and they all returned as ‘Lockpick’, but if I already had 1 (or 2 in medkit’s case since that was default) then nothing gets added but it just prints out as either itself, none, or another item name and says that it’s already in and stackable.

Hey, one problem in the top branch is that you override the existing Map entry with a new value, you are not adding the items together. The ADD node will override existing entrys when they already there.

The branch in the top does the exact same as the branch in the middle (you find the name in the map and then get back the name from it, you can just use the name you have in the beginning, it will be the same).


Woah hey, you made that awesome inventory system in the marketplace? I was gonna buy it the other day but I genuinely can’t justify spending any more money on this project, so I’ve tried to create my own and now I’m in this mess, haha, I know what I want but I have no idea how to do it since I’m still pretty new to scripting and blueprints. From what I can tell, you’re saying all of my branches do exactly the same thing, which is pretty much nothing if I already have a copy of the item in my inventory? How would I fix it?

You need to add the stacks in the inventory (the find node gives you the current amount of items in the inventory) and the quantity together and then set it in the player inventory.
The ADD node doesnt actually add the amounts together it will override the integer that is currently in the slot with the given name with the new integer.

I added my “Add item to inventory” function from my system, maybe it helps you to make your system.

You can ignore the first two sequence outputs, they are to increase performance and UI stuff.

The “Try to add stacks to slot” function does what i described in the beginning but additionally takes max stack size etc. into account.
“Set Inventory Slot” would be your ADD node from the map. Im just doing additional stuff regarding my stat system in there.

Yeah you’re overwriting the (key) entry with the current quantity.

If in TMap Array (FIND) -> Get Key -> get current Quantity -> Increment -> Overwrite current key (Add) with new quantity (value)

Awesome, thanks guys! :smiley: I’ve fixed the main issue now so the items stack properly, and show the correct names, so the only thing that isn’t working is adding items that aren’t stackable as a new entry, not sure how that’ll work with maps though? Since there can only be 1 entry to each key name you can’t have multiple ‘M4A1’ items in the inventory for example since they’ll have the same name, I currently don’t have any widgets set up though, I don’t know where to start since it’s my first complex menu system I’m making.

I’ll try and work out your ‘Add Item to Inventory’ function in the morning, but from a quick look it looks like you have a set number of items slots in the inventory? And a variable to set the max number of each item in a slot? I think my inventory works slightly differently to that. My system works so I have one BP_Lootable actor which is every single item in the game that’s lootable (it can be set to a specific item or set to randomise on spawn (I’m going to add functionality to be able to filter the items it can be randomised as based off of other variables in the database, I want to get the inventory to work first though)), it uses the item database structure to give it a name and all of its variables, including an item type, which can be anything like a weapon, equipment, crafting component, valuables, etc… and each one will show under a different tab in the inventory window, and each tab will have its own parameters, for example the ‘Weapon’ tab will be limited to 8 slots but can be upgraded by levelling up, whereas the other tabs have an unlimited amount of slots, and the slots (and tabs) are only added when necessary if you have the item in your inventory. The only items to have a limit are weapons, which are limited to 1 and not stackable, ammo, and equipment, everything else has no stack limit. Each item has a rarity too so the outline colour on the slot would change depending on that, but I’m sure if I figure out getting the items into the widget that shouldn’t be too hard.

Here’s a video of my design I did in photoshop because I don’t know if I’m explaining it well at all, haha, I want to hopefully make it so it’s modular and fully customisable so I don’t have to worry about an inventory for any future projects too, do you know where I would start with the widgets, or even how to get the ‘Player Inventory’ and use that to add items to the UI?

If you want to be able to have the same item multiple times in the inventory you should switch from a Map to an Array of structs. You can store for example in index 0-10 equipment, 11-18 weapons etc… When you add a item to the inventory you check if there is a item where it can be stacked to or an empty slot where the item fits in (e.g. when the item is a weapon only consider slot 11-18, if all are used then don´t add the item).

That is exactly what im doing in the picture except that i don´t check the item type and how many i already have of them. I just add them to an empty slot.

The UI can be much more difficult, you should start with a single inventory that shows all items at once to make sure the core works. Then you can filter out specific item slots or item types to build the UI you want.