Download

Inventory: Item(s) not appearing in player inventory

I have been following the tutorial from Ryan Laley and I put my own take on the concept of an inventory system ( loosely based on The Witcher 3 meets Outer Worlds). My only problem is that I cannot get the items I pick from the container to go into the inventory component of my character.

I am away from the computer I use to get the blueprints up but I want to ask is there any other simple way of just getting the information for the item I pick up to appear in the inventory of the player character?

I am looking for just a simple general setup and understanding of what to use and how. I will provide Blueprints later on, but please help me out here; I have been struggling with this issue (believe it or not) for more than a year! Aside from this and targeting, there is nothing else I have more of a problem with.

Please anyone has anything at all to offer, I will so much appreciate it; Thank you in advance

NOTE: I will get to uploading my setup but it is a lot to unpack.

Hopefully someone offers their help. This is a promising project.

1 Like

Okay here are the Blueprints as many as I can gather; you’ve been warned







…

This set is from the Inventory Component based on the tutorial series:










NOTE: There was one video that featured a fix to the add to inventory function; however even trying that did not work. So on top of an already broken inventory system, I tried implementing a new solution that didn’t work either. I’m not saying these solutions aren’t working; I know it’s something I’m doing wrong, so hopefully someone can see where the issue lies.

I could be wrong here, but in your second screen shot when you are adding to the inventory and connecting up the slot structure, you have 0 as your quantity. Try adding 1 to the quantity instead of 0.

I began my inventory using this same tutorial but have since heavily modified it to suit my project so it no longer looks quite the same, but if I remember right, this may be your issue.

1 Like

Tried it, same result. Honestly this is everything I got; I’m really at a loss here.

An inventory is simply a list of what you have and how much of it you have.

For example, to make a grenade inventory, you only need to store one thing: the number of grenades the player has. When the player equips a grenade, if the grenade count is greater than 0, you spawn a grenade and decrement the count. Once the count reaches 0, you don’t spawn anymore grenades. To give the player more grenades, you set the count to something higher than 0.

To extend this to have different grenade types, you simply add another variable that stores what type of grenade the player has, and when you spawn a grenade, you spawn that type of grenade.

1 Like

I’m more interested in the information on the type of grenade. carrying over the data from that item over to the player’s inventory. I hope the images I’ve shown give enough on what is done.

The inventory should only store what’s necessary to keep track of what the player has and how much of it they have; all other information should come from the item class. I see there’s a thumbnail variable in your code; that should be stored in the item class, not the inventory.

1 Like

The thumbnail shows up though. All the details of the item specifically picked up come up blank or as the default values. It won’t show the name of the item, it’s value or price, description, etc …
Could you be more specific as to where you see the thumbnail being used? Forgive me if I am being difficult, just trying to make sense of my mess :slight_smile:

I haven’t seen the tutorial you used and have only skimmed your pictures, so I don’t know if what you have is necessary or not, but it looks way more complicated than it needs to be.

  • The actual inventory is an array of “ItemStructure”. ItemStructure has way too many variables. All it needs to have is the class reference and any variables that changes during the game (e.g. ammo). The inventory should only contain what is necessary to manage the inventory.
  • It seems you’re mixing UI code with gameplay code. You’re only going to use the thumbnail for the UI, so why is it mixed in with gameplay code?

Honestly, I would suggest starting from scratch and keeping it simple (just adding and removing items). Understand that an inventory is only a list of items, not the actual items themselves (e.g. 1 stick, 2 grenades, and 5 bandages). When you need to get information for an item, you get it from its class because the class is the actual item.

I was referring to where you store the thumbnail in the code, not where it’s used in the UI. I was just saying that the thumbnail should be stored in the class, not in the inventory because its not necessary to make the inventory actually work (the thumbnail is cosmetic).

1 Like

I was afraid to do that. I agree with the inventory is basically a list, and the thumbnail not needing to be there. Now I am not sure where to start because I had something going on. I was making some progress, and now it just repeats results and I’m mixing things up and getting the same thing; and once I do so again, it’s all gone. The items were an array so that there’d be many different types of that item.

So here is the struct for the item itself; basically all the things I thought about putting in the item:

It’s the same as the tutorial; I only added the price, and the is quest item.

Trust me, I do it all the time :smiley: . You don’t necessarily have to make a new system; you can just start over and make sure everything works as you go; that way, when something doesn’t work, you know exactly what it is.

Start with just adding and removing entries from your inventory array. Don’t try to worry about UI yet, just get the actual gameplay side down first.

Okay, Yeah I did something like that; here:

The function was in the base Item which I also used in a Container; The difference is the item to add in the the two pictures.

I tried something as simple as an add with a set array element to the player inventory and print string to show the length of the array. Then I set the item of array elements to be the item that I wanted to add (for example, an herb or whatever). the print string worked so the array was being adjusted in real-time (I really hope I’m making sense here). So something IS happening; however, I saw that the length of the array was increasing, but exactly what was being added to that array remains a mystery since nothing appeared.

So now I’m beginning to wonder …

could the UI be the problem?
I began to acknowledge that the menu is where I want the item to appear in a list. I was beginning to wonder; is the UI even receiving any notification to update? For one thing the tutorials’ inventory window was in-game, while mine was in a pause menu.

.

Also I have a widget switcher set up that switches the widget based on the button you press. So within that menu widget is a another widget. Meaning that Inventory widget is within another widget.

Also meaning while his menu was open, the game was not paused like in Dark Souls or an MMORPG for example, and mine was (again, REALLY hope I’m making sense here).

You can print a variable from the array to check if it’s adding the right thing.

The way you’ve described it, it could be. Do you have it to where the player is actually holding the items? If not, I would suggest getting that working first.

The UI should be reading from the player’s inventory. And when the player moves something in the UI, it should tell the inventory to update.

I think pause just disables all ticking and pauses the game time, so it shouldn’t be a problem.

1 Like

You mean like holding a weapon? Not really. I mostly wanted to work on items like potions or something that effects the player’s stats. I did manage to make a weapon select menu and it’s barely polished, but it does spawn the weapon, although I treated that as it’s own separate task.

Here is what I did for the UI: remember, the inventory widget is within another widget.

This one is the function setup in the in-game menu widget that houses the player inventory widget.

This the function being called from the player character:

This was from earlier which gave me the results even though nothing was showing.

Well that should make it easier. Also, I just saw the beginning of the Ryan Laley tutorial you’re using, so I see what you’re going for.

You shouldn’t have the add item logic in the UI, the UI should be calling add item on the player, like the last picture.

Understand, when I say inventory, I mean the array. The UI should just be displaying what’s inside that array; the array shouldn’t need the UI to add or remove items. When the player does something in the UI, the UI should call the “add/remove item” function on the player’s inventory, and the player’s inventory is what actually does the add/remove.

Right! Here’s what I did now; I am gonna give it a test to see what happens and respond back:

The following is from the Actor Component:

The next is from the base item actor itself:

The last is from a Container that houses the items so I wanted to see if the item information would be shown. It did display the name of the item I wanted to add/ insert into the array, but again, no visible result in the menu UI as far as I can see.

So it’s probably a UI problem. How is the UI reading the inventory?

1 Like

Okay I managed to get some actual progress !!!

for your question, I had the menu hold a submenu page.
The Inventory was a submenu page and I think because of that it did not update properly.

I decided to just carry the code from the inventory submenu page over to the main in-game menu page and have it update the inventory submenu page from there.

This was the setup I got based on the tutorial:

And here is the In-game menu widget setup; this one is more makeshift, and loosely based on several other tutorials:

I had a feeling with the layers of widgets put up updating the UI information wouldn’t happen as fast as expected if at all.

So elements were being added / inserted into the array, but what information did the elements contain? sadly nothing.

Next was to update the elements of the UI inventory from the inventory component and the base items and containers.

Basically the inventory component is an actor component, and that function for adding to inventory would house the functioning for any item that uses that function. ie if the base item is being collected, it will tell the actor component to perform the function of adding the item to the player inventory and set the elements based on the details of the item itself.

The setup went as followed:


Basically both the item and Container share the same function of collecting items, don’t worry, they don’t both perform it at the same time :slight_smile:

SIDENOTE:
(Not that important): Get component of class was attached to another add to inventory function that was from the tutorial series. After the progress I was making I wanted to see if my setup was in some way compatible with tutorials’ design and it wasn’t, so I stuck with what I got for now.

NOTE: I noticed the item appears twice in my inventory; not sure why. The only thing I can thing of is that the function of setting array elements is being called more than once somewhere or there is an extra loop being run somewhere.

Another issue is that the items repeat. By this I mean that every item in the inventory is the same one item.

I’m not really sure what may cause this one …

This is in game capture, before the function:


Now there are only two items present in this menu:

The following is the after; as you can see, the items from the container are in the inventory, however, sometime they will repeat, and it’s only after a second or third press of the button:

Edit: Wouldn’t you know it I just managed to fix the repeated items issue!: So in the main tutorial I just plugged in the index into the Get of code I put in the in-game menu:

(This is where the setup separates itself from the other one).

I am so very close to completing this; All that’s left is the repeating of the items, and then other features like stacking items and adding items for crafting, and removing them.

ONE LAST NOTE I SWEAR FR THIS TIME: Okay so the items do appear, the function does are being carried over to the array/ list. however, the items still repeat, and despite there being nothing in the items’ array list, the action can still repeat, creating an infinite number of entries in the inventory list. Aside from that, there is also the items not appearing until the proper input is pressed another few more times.

1 Like