How to add items to inventory component? (C++ or Blueprint)

I have an inventory system that I made by following a tutorial but I’m having trouble trying to figure out how to add items to it. I already have an interaction system where I can press E on an item to get it to fire a function, all I need to know now is figure out how to add items now.

(Someone said I needed to use a TMap but I wasn’t sure if I had to delete my original inventory system to get that to work)

image
This is my inventory
image

This is a repost btw because it’s been like 10 days since I asked this

Since your inventory seems to be an array of actors, it’d be a matter of adding an actor who is the target of the interface message to the inventory array. Have the Start Interact return an actor’s (here, BP_Beans) reference (modify the interface function to return actor refs), and have the player add the item to their inventory.

Hey thanks for the reply, I made the start interact function return an actor but now I’m just confused on what node I would use to add the item to the inventory? If you could maybe send a screenshot example of how that would look it would be a lot easier to understand (if you can’t that’s fine too)

I also got an error after doing that but I’m assuming its because I didn’t connect anything yet?

Remove the above event, and re-implement the interface function - you will end up with a function instead of a custom event.


We have no clue how your inventory works; is it a component you added to the player BP?

  • lets say this is your inventory component:

image

  • interface implementation in the pickup actor:

image

  • player picks up an item and asks the inventory component to add it to the array:

There’s no need to the send Player reference to the item - beans should not care who the player is.


I had to assume a lot - not sure what we’re really working with but that’s what I’ve gathered.

Oh yeah I probably should’ve elaborated on that (bare with me here because this is my first time making an inventory system so I’m not even 100% sure if this is how it works) But I have a header file called item and it holds all the data for every individual item such as the thumbnail for example, I then have children of that class that has data for a specific item like the BP Food Item (In the inventory component array). Then all these items get initialized in an inventory component that’s in the player character I think? I’m just gonna send screenshots if none of that makes any sense. ( I followed a tutorial on how to make this if you couldn’t tell)



image

if you do not want to store actual actors in the inventory, store just their data. What I suggested should work fine here, one way or another.

I’ve been trying to follow along with your screenshots but when I try to add the “self” node it won’t let me because the graph is read only, how did you turn that off?

This is the interface. The implementation of its functions goes into the Item actor (where you saw an error earlier on). See my 2nd screenshot - I am doing it inside the item itself.


This is also the place where you could decide whether this item can be picked up to start with, and what happens to it after. Any item class can implement its own logic - you would not want to pick up an entire tree and put it in the inventory, for example. Perhaps a tree would return some data to indicated that, or even return some edible fruit instead.

1 Like

Sorry I’m just slightly confused because in your “Pick Up Item” function it says the target is BPI Interact and my target says BP Beans which doesn’t seem right. I also don’t seem to have a reference to the “Pick Up Item” function in the player graph which I don’t know how to get.



Also when I try to connect the New item node to the add node it says it’s not compatible

You had it working here already:

image

But interface functions with no return turn up to be events. Your function is called something different:

image

It’s already there on the screen - Start Interact - call that.


And you’re trying to implement this:

In the menu. Double check my screenshots - this part belongs in the Inventory. It’s the inventory that stores items, right? Not a menu. And you’re dragging the blue wire on the wrong pin.

1 Like

Oh yeah I named my blueprints kind of poorly (I followed a tutorial and that’s how the guy named his blueprints) I wasn’t sure if I was able to add functionality in an inventory component? But the main menu is the UI that shows the actual inventory here.



And this is the functionality of the “Menu”, would this be considered the inventory? Or would I have to make a separate graph for adding items?

Also the “Inventory” nodes are a reference to the inventory component

Also I meant to drag the blue wire to the other pin in the screen shot, (it still gives an error)

Again, this does not belong in the menu. Your inventory is right here:

image

In the player BP. The inventory should be responsible for managing items. Why is the Main Menu even involved in this to start with? Consider restructuring it so it makes logical sense unless you have a good reason for handling it this way, ofc.


Regarding the error - it explains the type mismatch; ensure you’re adding a matching item type to the array. Have the interface return Actor type for now, same for the inventory array.

Sorry for the late reply I’ve been trying to wrap my head around this, I was under the impression that the menu was the inventory, but I suppose not. I was trying to get in the inventory component like you showed me but it turns out I have it set up in c++ not blueprint(So I don’t think I can edit this in BP or else it’ll mess something up but I’m not 100% sure, I also tried turning the class into blueprint but I got some errors).


So I think that’s why I’ve been kind of confused, do you know how I would go about doing this in c++ instead?

This is also the video I followed to make the inventory, idk if this will help. https://www.youtube.com/watch?v=-WNwo-riV1Y&t=1664s&ab_channel=reubs