Godot: Mouse Position is unknown until first mouse event

Created on 25 Mar 2017  路  23Comments  路  Source: godotengine/godot

Operating system or device - Godot version:
Linux - Godot master (468719)

Issue description:
If you neither click nor move the mouse, get_global_mouse_pos wil return (0,0).
Related to #8136.

Steps to reproduce:

extends Node2D

func _ready():
    print(get_global_mouse_pos()) # 0,0
bug confirmed junior job macos core

Most helpful comment

Should now work on Windows and Linux, only macOS left.

All 23 comments

Maybe related to #5051 and I think there are other issues like this related to the initial mouse status, all need an input to start getting the correct value (position,hidden).

Can someone confirm if this issue happens on non-linux platforms as well?

Can confirm on Windows 10, with stretch mode disabled.
Stretch mode 2D gives a different output for both local and global: (-1.#IND,-1.#IND)
Viewport mode is not working but it shows 0 or -1.#IND on the output on different aspects.

confirmed Windows 7, latest master built on linux mingw
Non-stretched: (0,0)
Stretched 2D: (1.#QNAN, 1.#QNAN)

When stretched there is also a ton of messages "mesege" and a lot of errors

Just created a patch for windows.
When Stretch 2D is enabled, then get_global_mouse_pos() returns NAN even after the mouse moved, so it should be moved to a separate issue thread

Reopening since it isn't confirmed to work on MacOSX properly yet.

Also for:

Stretch mode 2D gives a different output for both local and global: (-1.#IND,-1.#IND)

I think the current fix mitigates it, but it might still happen that the mouse position is really (0, 0), and in such case it should not do divisions by 0.

@akien-mga

When Stretch 2D is enabled, then get_global_mouse_pos() returns NAN even after the mouse moved, so it should be moved to a separate issue thread

I guess we might indeed branch it off in another issue.

@bojidar-bg I could implement the same logic of pre-processing events before main->init for all platforms

@sergey-push seems like that wasn't a good solution, we'll need to think of something else: https://github.com/godotengine/godot/pull/8291

Any progress on this, guys?

Is it only on X11 or on Wayland too?

@alugarius we don't have a Wayland backend..

I can confirm the issue on Linux (Mageia 6 x86_64). Not critical for 3.0 though, moving to 3.1.

I'm getting this issue on Mac, with Godot 3.0.2. (Running MacOS 10.11.6)

@hpvb can you check this on linux?
Who is working on mac bug fixing btw?

The X11 part is fixed by #21910.

Similar fixes need to be done for Windows and macOS.

Should now work on Windows and Linux, only macOS left.

Going to work on a solution for macOS

Can someone else on macOS confirm that this is still an issue? The mouse position seems to be correct on startup for any test I run.

CC @bruvzg

Indeed, CanvasItem:get_global_mouse_position() return 0,0 when called from _ready, moving or clicking is not necessary to set mouse position, is set after the first frame.

func _ready():
    print(get_global_mouse_position()) #print 0,0
    yield(get_tree(), "idle_frame")
    print(get_global_mouse_position()) #print real mouse position

Fix similar to X11/Windows works on macOS as well. PR: #29876

Was this page helpful?
0 / 5 - 0 ratings