Drag and drop not working with control and cannot find why

Godot Version

v4.2.1.stable.mono.official [b09f793f5]

Question

Hi, I’m stuck with a UI problem. I try to use the built in drag and drop feature from control object. I already done it before and it work well. In my current project I don’t know why, I can start dragging an object but cannot trigger the _CanDropData and _DropData function when I’m hovering the destination UI control.
I don’t know how to debug and find out which element is blocking the Mouse event but surprisingly the OnMouseEntered and OnMouseExited work fine while dragging.
Here is the tree of my menu and the one from my Item that can be dragged :

Inventory scene

All control have there Mouse filter set to the default.
Every tool# node are instance of this scene :

Item scene

Tool_tree

In this one, All child of the control root have mouse filter set to Ignore.

I have already try to remove other control from the inventory but not work either.

My item drag and drop checking is set like this :

Drag drop
public override void _DropData(Vector2 atPosition, Variant data)
    {
        GE.Debug(this, "Drop",data);
    }

    public override bool _CanDropData(Vector2 atPosition, Variant data)
    {
        GE.Debug(this, "CanDrop",data);
        return false;
    }

    public override Variant _GetDragData(Vector2 atPosition)
    {
        GE.Debug(this, "Drag", this);
        return this;
    }

What I have try so far :

  • Remove other control from my menu to see if anything overlap
  • Create a simple script with the same drop function as before to add on every control and check if anyone receive something (but don’t …)
  • Change the type of object return by my _GetDragData function.

Thank by advance.

Because I can’t know how you wrote it, I can only suggest you debug it line by line.

If you are willing to provide more details about the code, I think we should be able to understand what’s going on.

Well I have continue my investigation, it seem that it’s not my menu who block the drag and drop but the split screen system. I have made a small project showing the problem :
https://www.swisstransfer.com/d/c95bb286-fbfe-40ff-86b9-58e6a1d35092

If you launch the DragDrop scene only, it work well. But if you launch the Main scene it don’t work. Don’t know how to change this…

Well, it’s a current godot problem…

My tree looked something like this in my main scene:

  • Root node
    • Sub viewport container
      • sub viewport
        • instantiated scene

When launching the instantiated scene on its own, drag and drop worked fine. When launching the main scene, the _get_drag_data call would happen just fine, but no _can_drop_data or _drop_data calls would happen. I even found that if I managed to click the same button I was holding down (left click on track pad while holding left click on mouse) I could manually trigger the _can_drop_data and _drop_data calls, but otherwise they weren’t happening.

Long story short, the subviewport was the issue. There is an option under the GUI section of the subviewport settings labeled “Embed Subwindows” that is not checked by default. Checking this box caused the drag and drop of the instantiated scene to work just fine and fixed this issue. I figured I’d leave this hear for anyone else that ran into this niche issue.

TLDR: If drag and drop issues are happening when something is in a subviewport, try enabling “embed subwindows” under GUI in the subviewport node.

1 Like