Hi, I’m working on a 3d 1st person game. I use Input.MOUSE_MODE_CAPTURED for the camera with no issues.
I’m implementing the pause menu now, and because the menus can be navigated with controller or only keyboard as well I wanted to hide the cursor unless a mouse input was detected. The problem is that the cursor is always visible for a frame (maybe a few) when you pause the game.
My code is this.
func _input(event):
if get_tree().paused:
print(event is InputEventMouse)
if event.is_action_pressed("ui_cancel"):
if $VBoxContainer/Exit/Panel.visible:
_on_cancel_pressed()
else:
_on_resume_pressed()
elif Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE and not (event is InputEventMouse):
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
print("1")
elif Input.get_mouse_mode() == Input.MOUSE_MODE_HIDDEN and (event is InputEventMouse):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
print("2")
elif event.is_action_pressed("pause"):
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
get_tree().paused = true
$VBoxContainer.show()
$VBoxContainer/Resume.grab_focus()
The console always shows “true” once, so “event is InputEventMouse” is true even if I don’t touch the mouse.
If I replace InputEventMouse with InputEventMouseButton the problem is gone, but if I use InputEventMouseMotion the problem is back. I suspect InputEventMouseMotion is being detected when it shouldn’t, but I hope someone with more knowledge about this helps me understand why this happens and how to fix it.
caused my control root node to not respond to input I used a bool instead and code works great, prints false when the pause button is released.
I sadly can’t seem reproduce the issue.
Initially I thought grab_focus() might generate a mouse event but rather it seems to be the role of its counterpart grab_click_focus(). It might be worth a shot to check if it’s definitely involved or not be commenting the last line.
Thanks for the suggestion, but sadly the issue is still there. I assume that maybe changing the mouse mode is what might be generating the mouse event, but if that’s the case then I’m not sure how to change from captured to hidden while allowing a mouse input to change it to visible.
Out of curiosity what platform are you on ? I don’t know much about platform specifics but sure mouse
Making a standalone quick single Control test scene, would the bare minimum of your code works ?
extends Control
var paused := false
func _ready():
pass # Either VISIBLE or CAPTURED from start works
#Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if paused:
if Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE and not (event is InputEventMouse):
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
elif Input.get_mouse_mode() == Input.MOUSE_MODE_HIDDEN and (event is InputEventMouse):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
elif event.is_action_pressed("pause"):
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
paused = true
This works for me on linux kde plasma wayland session, if it works for you it’s just some other complexity abstraction getting in the way or if doesn’t we can assert there might be some platform discrepancy.
I’m on Windows 10, and sadly your code has the same effect than mine. I tried with only your code and still when the change happens the arrow shows up for an instant and then disappears until I move the mouse.
Actually, I just tried to run only that scene and I think I found something. With your code it works fine, but with mine it only works the first time I pause. If I unpause and then pause again the problem is back. The only difference that I can see is that unpausing sets the mouse mode to captured, while the first time the mode was visible since the game scene where I set it up to captured didn’t run.
Edit: Just to confirm this, I removed the comment on your code that sets the mouse mode to captured and the issue happens again, so I guess it definitely has something to do with it.