GlobalMousePosition not getting updated few frames if button is pressed

Godot Version

4.4.0-beta as well as 4.3

Question

Hi there,

I’m trying to implement simple dragging logic. Everything works fine, but when I start dragging after the initial mouse button press, I’ve noticed there a slight lag. I’ve tried to log the values, and get_global_mouse_position() simply doesn’t get updated much during the first ± sec, after that, the dragging is smooth.

Any ideas?

Here is my most simple code snippet.

using Godot;
using System;

public partial class Icon : Sprite2D
{
    private bool _isHovered = false;
    private bool _isDragging = false;
    private Vector2 _dragOffset;

    public override void _Ready()
    {
        var area = GetNode<Area2D>("%Area2D");
        area.MouseEntered += OnMouseEntered;
        area.MouseExited += OnMouseExited;
    }

    public override void _Process(double delta)
    {
        if (_isDragging)
        {
            GD.Print(GetGlobalMousePosition());

            GlobalPosition = GetGlobalMousePosition();
        }
    }

    public override void _Input(InputEvent @event)
    {
        if (@event is InputEventMouseButton mouseEvent)
        {
            if (mouseEvent.Pressed && mouseEvent.ButtonIndex == MouseButton.Left && _isHovered)
            {
                GD.Print("Pressed");
                _isDragging = true;
            }
            else if (!mouseEvent.Pressed && mouseEvent.ButtonIndex == MouseButton.Left)
            {
                _isDragging = false;
                GD.Print("Released");
            }
        }
    }

    private void OnMouseEntered()
    {
        GD.Print("Entered");
        _isHovered = true;
    }

    private void OnMouseExited()
    {
        GD.Print("Exited");
        _isHovered = false;
    }
}

I copied your code and I don’t see any lost frames.

Can you show how it looks like in your game?
I don’t think this piece of code is causing the lag, maybe it’s somewhere else.

Huh, interesting. Could it be because I’m using Mac?

It’s a new project with only logic being the script I’ve provided.

As a new user I could not upload video directly, so here’s the link → https://www.youtube.com/watch?v=SQlApPgmAEs&ab_channel=Tacaxs.
Hopefully it can be seen there, that there’s initial lag if I click on the node and start quickly dragging.

After that, the drag is relatively smooth.

I’ve also tried to highlight the logged (pretty unchanged) mouse position during the initial dragging.

Hmm, I have an idea - it seems like the Shape2D in your CollisionShape2D node is really small, because you are exiting and entering the shape during the drag. Can you try to make it bigger and see if this helps in any way?

Gave it a try and that was not the reason. But if you check the logs, you can see that they show the same positions for GetGlobalMousePosition in the first few logs (thus the lag in my opinion).

My uneducated guess would be that the processing of mouse movement is somehow delayed after the first click for some reason, cuz I’m always getting the same value when Process functions runs, even though the mouse is clearly in different position.

Is your Mac above the minimum requirements?
I dint really see any other explanation for it, sorry. Maybe you want to report it on the Godot GitHub as a bug.