I just finished building out the ‘drag and drop’ functionality of my inventory system. But, I was wondering if there is also a way to allow players to swap items by clicking one widget, and then clicking the widget they want to swap with. How could this be implemented?
Hi @DaddyFarquaad69 ,
I never done this before, but I think you should save the index of both of the inventory. for Example when you first click Item A, then you save the index of Item A. After then, you Click Item B, you also need to store the index in the different variable.
In the end, you should check whether both of the indexes that you save is already filled or not (Filled means there are two item that clicked), If its filled, you just need to swap the positioning in the inventory itself (and dont forget to refresh the widget so the position also changed in the UI not only in the data).
I hope you get some insight from this.
With the ‘Create Drag Drop Operation’ node, you can use the ‘Payload’ to pass an object reference from the ‘Drag Detected’ function to the ‘On Drop’ function. How could I do this without the ‘Create Drag Drop Operation’ node? I would need some way to get a reference to both of the objects being clicked on in order to change their images and indexes.
I don’t know how your Inventory is constructed… what data is used to detect what item is inside a slot and how you show its icon…etc…
but…
Without a DragAndDropOperation.
when clicking on SlotA store the relevant Data into a Hold Variable(s) in the Gameinstance. Set a Bool in the GameInstance to true.
then, when clicking SlotB, do the same with a second (set of) Variable(s) in the GameInstance.
The hold Data could be:
the item name, to get data from a DataTable…
the item quantity…
The Indey of the Slot, the item is currently sitting in…
Now check if the bool is true. If yes, Set the Data of SlotA, to the Hold of B, and the Data of SlotB to the Hold of A.
Now empty the vatiables in the GameInstance and set the Bool back to false.
I’ve never used a game instance before, so I’ll have to do more research on this. Thanks for the suggestion.