Swapping places of sprites by dragging

I’m moving items in inventory by dragging them. There are few conditions to be met.

1.Upon picking up the item, move it to the first free slot. This works.
2.Allow player to drag an item on top of the other and swap their places. This works.
3.If item is dragged but not dropped on any slot, move item back to the original slot. This works.
4.Allow player to drag an item on top of the free slot and move the item there. This doesn’t work.

How do I make a difference from a free slot that item will be placed in, and a slot that item was dragged from, thus making that slot also free in the process. At the moment, item will always go back to the original spot it was taken from.

Your second to last place holder conditions. The one where the sub condition is fx =1. I’m thinking maybe the Slot.X Slot.Y isn’t specific enough in the subcondition events. Before deleting the placeholder, make a temp var or something with its position and move to that. Or even with the slot X slot Y there right above deleting the placeholder, where its collision check is fresher. Not 100% sure though.

If that doesn’t work it might be just setting the bool to false just dragging a spell icon over it (if that’s how its moving). Maybe do spell icon/collision slot/mouse released = bool to false.

I’ve tried using first solution but it doesn’t work unfortunately.

I’ve tried using booleans before, and tried now again but still couldn’t get it to work. I might be using booleans in a wrong way though. Can you please tell me exactly how did you imagine the solution?

Well I was just wondering if you drag the spell icon to the slot, that might be setting the slot boolean to false because it might count as a collision. If so then maybe the second to last condition isn’t coming true. So I thought you could try changing the conditions of your boolean to be if the spell icon is in collision with the slot and the mouse is released, then change it to false. But this is just conjecture I don’t even know if the spell is being dragged to the slot or triggering it to false that way.

It is being dragged to the slot. And it does set boolean of the slot to false. The original slot becomes true.Therefore, no real change is made.
I’ve already tried adding condition to check if mouse was released, but the issue remains. I have 2 conflicting conditions no matter what, since I’m also checking if slots are free or not before any clicks are being made.

Maybe some of this helps: Drag and drop with placeholders (sample project)

1 Like

You have so many useful examples! Tyvm <3

I’ve managed to do it on my own now. Didn’t have the chance to see the sample project, but will check it out right now to see if theres a better and easier way of doing it. Thank you anyway.

EDIT: Checked it out and its cool. You did it in a much different way than me. One thing that could be added if you want is to be able to swap places of the objects. But even like this it is great.