I created an inventory system, where I can get an item in the world, and its image is saved in the inventory. However, I am having difficulties in creating a system that “changes items”. Basically what I want to do is that with a button on the keyboard, or a controller, I can select the item in my hand. An example: I press I on the keyboard and change from the lantern to the key and continue
through the stots… (and this happens both in the widget, in the player’s hand)
With some tests I used AttachToComponent and managed to put the item in hand, but then I can delete it from the hand and take the next one, much less understand which slot this item is in.
You have an inventory made of arrays?
you can build almost anything in a various of ways but here a clue.
If you have an array of items,
An Item is a structure , it have a name, a mesh .
Placing or setting items in the array give them a Position in the array. so
If you place Item_KEY to index 1, then Item_Lamp in Index 2, basiccally you done it.
When you select an item , you can use a new variable, Integer, to take note of the item you are using.
Var Selected _item = 1 ,
So when you select an item , take note of that in the variable.
How search for the item?
Array have a nice features in LOOP,
Use a loopforeach, and attach it to the array.
It will get every item in it, and take note of the position by himself.
You jjust need to pin out the question like… Get name , And check (IF) is the one you are searching with == .
Basically you dont search for the items in your hand because when you place them , you Set a variable to remember you what you are doing.
Like: Spawn Lamp and attack actor to soccker… Then Save the reference to the lamp, and set the Variable “Left_hand” to (Loop in all your inventory–if is a lamp get the Index)