Skip to content

GUI mouse release inputs get lost if the target node is reparented #82271

@wareya

Description

@wareya

Godot version

4.1.1

System information

Windows 10, amd rx 480 gpu

Issue description

If you reparent a node while the mouse is moving after being pressed on it, it loses that state and never receives a release event.

This other issue is related, but is about node removal/visibility change, not reparenting: #43400 -- They might have the same underlying cause.

I ran into this while trying to make a graphical code editor where reparenting control nodes by dragging them is a basic operation.

Steps to reproduce

Create a "draggable" Control node with your own drag logic using _gui_input and mouse input events. Reparent it when the input is "pressed". It will fail to receive the release event. This causes a half-broken gui input state where other nodes can receive relative mouse motion events even though the release event has never fired.

Example:

extends PanelContainer

const do_reparent = true

var dragging = false
func _gui_input(event : InputEvent) -> void:
    if event is InputEventMouseButton:
        if event.pressed:
            print("started dragging")
            if do_reparent:
                print("reparenting")
                var parent = get_parent()
                var pos = global_position
                if parent == get_tree().current_scene:
                    reparent(parent.get_node("Panel"))
                else:
                    reparent(parent.get_parent())
                global_position = pos
            dragging = true
        else:
            print("done dragging")
            dragging = false
    
    if event is InputEventMouseMotion:
        if dragging:
            position += event.relative

func _process(delta : float) -> void:
    modulate.a = 0.5 if dragging else 1.0

Expected behavior:

2023-09-24_18-11-58.mp4

Actual behavior:

2023-09-24_18-12-59.mp4

Minimal reproduction project

GUIInputTest.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions