Attempting to make an inventory system for my player...

From what little I understand, I think arrays are the way to do this, so I want to add items to an array of actors, however, I do not want the player to be collecting various bits of terrain and decoration, so I’m trying to limit what can and what can’t be put into the array through a series of branches, but I do not want to deal with the potentially hundreds of branches required to sort through every individual actor the player can acquire, so I’m trying to use an array of actors and see if any of the items my player’s line trace detects are part of this array of actor classes and then add it to the array of actors.
From there I’ll obviously need a way to sort the actor array since I would like the indexes of the items to match a particular order and not the order the player collected them. But I’m stuck because I’m an idiot with basically no programming experience:

I have discovered the “Contains” and “Switch on Integer” nodes… I feel like a goddess!

Create and add a blueprint interface to your item class (e.g. iPickup). Then just check if the linetrace hit an actor that implements iPickup. If so add it to your inventory.

Don’t add the actor just pass in a struct that has its class reference (the purple one) and the amount if stackable.

No need for class checks or casts.

1 Like

Create and add a blueprint interface to your item class (e.g. iPickup). Then just check if the linetrace hit an actor that implements iPickup. If so add it to your inventory.

Uhh, ok… How do I do that?


And a quick working example although just a proof of concept.
UI sorting & stacking is a more complex matter.

Left click objects to pick up, I key lists current items in inventory.

4 Likes