Inventory System

Hi,

what is the best way (Blueprint) to store the collected items in the inventory from left to right?

Screenshot_Inventory

Thanks in advance.

hi,
one easy approach would be to use a fixed array… like in this screen you have 5 slots. when you create your inventory slots from left to right, 0 if left, 4 is right…

you could now use a simple function which updates your slot items based on an array of SlotLength, lets call it ItemArrayForSlots…

now your slots have the same order as the ItemArrayForSlots (left to right)
for your slots you can GetChildAtIndex(x) from the Grid or have a SlotArray and use the same ID for them…

use a FOR loop and then simple set on change
GetChildAtIndex(x).ItemImage = ItemArrayForSlots [x].ItemImage
or
SlotArray[x].ItemImage = ItemArrayForSlots [x].ItemImage

because index 0 will always be left, if you add a new item and update your slots then the new item will be left and the others get shift to the right…

you can also add a new item to the end to inverse it :slight_smile:

what i forgot…
you can have more items, id stays the same and if you start from top left corner you can easily get your grid position ( in case you have more rows than 1 :slight_smile:

gridX = ArrayIndex % GridColumns
gridY = ArrayIndex / GridColumns

you can use a int point or have 2 integer for it…

i hope that makes sense… when i am back in the evening i can make a screenshot :slight_smile:

cheers :vulcan_salute:

1 Like

I would be very happy about screenshot :slightly_smiling_face:

hi,
yes sorry i will make them in ~1 hour… had so much work to the last days, i forgot yesterday :confused:

ok i am back… had a meeting, took much longer than expected ^^ posting soon

cheers :vulcan_salute:

1 Like

Thank you for your support! :slightly_smiling_face:
If you drop the items, they should no longer be available in inventory

1 Like

a little inventory as seen below :slight_smile:

2 Likes

You can use Array and a more refined approach would be to create linked list. Linked List is a data structure. When you pick up an object store it in 0th index of the array and when you pick the 2nd object store it in the 1st index and so on. And when you drop the 1st index object the 2nd index object should automatically move the place of the 1st element to make a more precise inventory system. Use a for loop to check which index of the array is empty and store an object there.
Hope it helps.

Perfect, More than I wanted :slightly_smiling_face:

1 Like

this is the result

ok so here we go… first i want to make clear this is NOT the best solution :slight_smile:
i made a struct which holds the item because i was too lazy to create a proper data table for it :stuck_out_tongue:

this will be our inventory ActorComponent





PickUp is the Interface Event :wink:





this is his very basic interface

the widget inventory itself



the inventory slot widget




this is the item actor, sorry for my laziness :smiley:


the item struct, which should be a data table

the item slot struct, which can be left if better invented

basic sprite material

and here is the sort function, if you drop a item it will resort the array…




this is a very very basic inventory and can be done much better… the calls for materials on the slots to update is not the best practice but i am sorry i can not spend more time with it… have too much work to do at the moment… but i hope some points of it can be a starting point to a real inventory :slight_smile:

the resort function can be left out, if you like it just plug it in as seen in the screenshots… and it would be good if you make a data table to hold all infos, then you can leave the material sets out… which i would have done if i have more time…

cheers :vulcan_salute:

p.s. if you have questions feel free to write me

3 Likes

now this is above and beyond a helpful response! what a guy!

1 Like

A solution from another dimension! More than perfect.

2 Likes

Do you have this in file format? Your solution didn’t work for me.

yes… what is missing ?

I don’t know what I did wrong. I did everything like in the screenshot.

you added the visibility to the slots and inventory ?

Inventory.rar (148.8 KB)
you can try copy it in… best in explorer so all files are in at once

p.s. the main folder is called Inventory, best if it stays in there or structs will go berzerk ^^

what did not work ?
for drag and drop the visibility layers need to be set… ill add that to the post

The collected items are not displayed in inventory

did you add the interface to the ActorComponent inventory ?
PickUp is called via Interface or you will get an InfiniteLoop

It worked, forgot interface :slightly_smiling_face:

1 Like

i wrote it in the post :slight_smile: you can make much more fields… when i have time i make a new inventory, i will send you the link then :slight_smile:

cheers :smiley:

1 Like

Super :slightly_smiling_face: :grinning: