how to swap items in inventory?

I have an inventory that I made with an array, I can get the index of each slot that I click on with this code

When I drag this slot, I am passing the index information of this slot to my drag and drop operation, and which item I am dragging, here:

ok, now I don’t know what to do, how do I get the index of the slot I want to replace and change it? inside the widget and the inventory, inside the widget I don’t know what to do, and inside the inventory i’m trying this:

Now I don’t know how to get the destination index or how to update the widget

hi,I didn’t read through the code.
arrays have a “swap” node.which asks you to provide two indexes.
after swapping the items.you can refresh the ui elements that represent the array(basically re-initialize themselves agin).
I hope it somewhat helps you figure it out :smiley:

1 Like

oh, wonderful, this works, but I need the index of the item I want to replace, how would I get this index from the widget?

It’s at the “on drop” function.this function is unique.
when you drop the item to one of those slots.the slot who received the dropping will call its own “on drop” function.then in the function you can get the index the slot contained.

I managed to get the index but now I’m having this problem with index 1 to 0, all the other indexes I can swap normally on them, but from 1 to 1 it doesn’t work, it keeps returning 1 in the on drop when I drop it on index 0

2024-10-28 01-11-24.mkv (25.4 MB)

blueprint setup:

In my inventory UI I get the index of each slot created and set it within the slot itself

inside the slot, when dragging, I store the value of the variable along with other

and on drop I get the new value from the slot I’m dropping it into

All right let’s debug.
The update widget and the dropping seem to be okay.

First in the drag detection.try not to use self as a visual parameter when creating the drag operation.you can create a new widget with the same look but without any collision.and then use that widget created for the visual.
because “self widget” has collision.and when you drag it ,it also able to receive dropping too sometimes if it has collision.

1 Like

oh, now everything works, thanks

1 Like