Reset widget slot position when placed wrong.

333400-dd.png

So, I’m trying to figure out how drag and drop works. As seen in the picture I have a horizontal box where I drag from and a box where I drop. I want for example the blue square only be accepted if it’s dragged on blue and so on, if other color is dropped on blue, make it go to its initial position. And this is what I can’t figure out how to do. How do I achieve that? Thanks.

Thank you, I’ll give it a try later and let you know if that works.

Each square needs to be a user widget and carry a flag (index, enumerator, nametag). If you have 4 - enums, if you have 40 - nametag, if you have 4000 - indexes). Each use widget implements onDrop:

When you start dragging, don’t remove the widget from its original position, hide it instead and create a visual for the drag OP. When dropping (or drag enters), query the IDs:

Compare the IDs:

  • if they match, reparent the payload into the new container - this will automatically remove the widget from its old parent as it cannot be in 2 simultaneously, return True.

  • if the IDs do not match, unhide the original widget (it did not even move, it was just hidden) and return False to cancel the drag OP.


make it go to its initial position

Essentially, smoke & mirrors. Nothing moves until you know you can successfully drop, if you can’t drop, nothing was moved so there’s nothing to return to initial position as it has always been there.


Also, have a look at my answer here, the one with wires:

The link to the project is still up.

Thanks, it works. I was not setting it back to visible when the color did not match. Now it works perfectly!