I’m making an inventory. Everything is working fine. I’m just looking for a way to drop an item outside of the inventory and spawn it back into the world.
Now I already have this working perfectly.
The only problem is when i drop my item on another slot, it also spawns it in the world everytime.
The way I currently detect if an item is being dragged outside of the inventory is by using the “On drag cancelled” event from drag and drop operation.
Now this always seems to fire when I release my dragged item (widget), regardless of it being dropped onto another slot. Now how would make it so cancelled it only called when there is no drop event?
I don’t think its a good idea to handle spawning actors inside the “OnDragCancelled”. This will always fire, even if the player obviously wants to do nothing.
Instead you should make a canvas widget that has all the screen space, and in it, handle drop operations by spawning the actor.
That widget should obviously ignore anything else - and not have a texture. Also the canvas must have a lower Zorder than your inventoryslot widgets
Then on the OnDragCancelled you can actually handle what happens when the drag is cancelled (maybe nothing?)
Also - I think that the reason it fires even when the drop is successfull is because you are not using the return nodes. You should use a “true” boolean for return value when the drag was successfull on your first screenshot
Oh and the reason why I use “drag cancel” is because the slots I have in my inventory are all placed next to eachother without any space in between. So technically you can’t cancel your drop. You can only drop it on a another slot, or when you are not dropping it ot another slot you are always droppig it out of the inventory basically in which case it needs to spawn in front of the player. But I see what you mean. In case I had an inventory with big borders and padding or something, there could be a scenario where you would accidently drop it on that and you’d want the drag operation to be cancelled and the object to return to it’s previous slot. But as mentioned my inventory has no spaces in between. It’s either a slot or nothing. And in case of nothing it always needs to drop in the world.
Glad you fixed it.
I was mostly talking about giving the player a way to cancel his operation. (He might want to do so with right-click or “esc”). Something user friendly and intuitive. But I guess that’s up to you and your game - if it works for you then it’s fine!
Yeah true. Well, right now the inventory works perfectly fine the way it is. But if a need for a cancel arrives I will definitely consider your advice!