Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse Input not detected in SubViewport when switching to MOUSE_MODE_CAPTURED while mouse is outside of the window #84389

Open
MikaSchoenmakers opened this issue Nov 3, 2023 · 4 comments

Comments

@MikaSchoenmakers
Copy link

Godot version

4.1.1

System information

Windows 10, NVIDIA GeForce GTX 1660 Ti, Forward Plus

Issue description

When using a SubViewport and changing the mouse mode between MOUSE_MODE_CAPTURED and MOUSE_MODE_VISIBLE, it will not detect any mouse inputs unless a mouse button is held down.

This also happens when alt-tabbing and the cursor is outside of the window, but only after the mouse modes have been switched at least once.

Video:
https://github.com/godotengine/godot/assets/95089122/5e2d76ad-9120-43b6-9fa4-bb4170833699
First the mouse is working fine, then I switch to MOUSE_MODE_VISIBLE, move the cursor outside of the window, switch back to MOUSE_MODE_CAPTURED, then mouse inputs are no longer working unless I hold down left click.

Might be related to #84258, but I'm not sure.

Steps to reproduce

Create a new 3D project
Set the project to run in fullscreen
Add a SubViewportContainer and a SubViewport, set to fill the whole screen
Add a player character with basic mouse movement and a camera
Add a way to switch mouse modes between visible and captured
Add a box in front of the player for reference when moving the mouse
Run the project, change the mouse mode to visible, move the cursor outside of the window (bottom left), then change the mouse mode back to captured.

Minimal reproduction project

MRP.zip

@AThousandShips
Copy link
Member

Can you please try this with a supported version, like 4.1.3 (only the latest patch version is supported, and it might already be fixed)

@MikaSchoenmakers
Copy link
Author

I just tested it, and this is still happening in 4.1.3.

@JuanFdS
Copy link

JuanFdS commented Jan 31, 2024

Can confirm this also happened to me in 4.2.1.

Also, @MikaSchoenmakers have you found a workaround?, currently I'm trying this:

  • when the window gets focused again (I connected to the window.focus_entered signal), I set the mouse_mode to Input.MOUSE_MODE_VISIBLE for some frames and then I change it back to Input.MOUSE_MODE_CAPTURED again.

And that seemed to do the trick

@alexjhetherington
Copy link

alexjhetherington commented Mar 26, 2024

Seems like it should be a common issue for games where you directly control characters and you are using viewports for full screen shaders. Surprised this doesn't have more thumbs!

My work around, on an Autoload singleton

func _notification(what):
	if what == NOTIFICATION_APPLICATION_FOCUS_IN:
		fix_mouse_input()

func fix_mouse_input():
	if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
		Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
		await get_tree().process_frame
		await get_tree().process_frame
		Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants