I’m making a PAUSE SCREEN whose process mode is WHEN PAUSED.
This PAUSE SCREEN is showed when PLAYER presses ESC in game scenes.
And everything works just fine except one thing:
This is my code and my confusion:
func _input(event: InputEvent) -> void:
if event.is_action_pressed("left"):
print("left")
The code above can show this _Input function is working well,
printing “left” every time I press A
if event.is_action_pressed("pause"):
print("esc pressed")
hide()
get_window().set_input_as_handled()
For now the second piece of code is not working.( and not printing anything)
It seems that it stops recieving any ESC action
Cuz when I change “pause”(which is ESC) to other actions like “right”(which is D),
this will function correctly.
BTW, “ai_cancel” dosn’t work as well
I think this has something to do with the _unhandled_input function I called in “player.gd”,
in which there is also a line “if event.is_action_pressed(“pause”):” to show the pause menu;
Or the same line I used in “menu.gd” to quit the game in title screen
What I want to do is hide the PAUSE SCREEN when ESC pressed.(I’m sure I have binded ESC to “pause”)
But if it is set to always, _input function is excuted before _unhandled_input function.
And I use _unhandled_input function when the game is running to call the pause screen
So the _input function in pause_screen.gd will capture the ESC action first and the _unhandled_input can not get the ESC action?
(and the pause screen can be displayed and hidden when its mode is WHEN PAUSED with my script)
Actually the problem is not with how to pause because pausing works correctly in my script.
The problem is this _input function seems to ignore ESC action while other action like ui_accept, ui_left all function properly. So I’m really confused.
But thank you for that.
And apart from this .gd file, I only used _unhandled_input to deal with ESC action once ,which I’m sure is not working while the game is paused. And _input should be excuted before it.
I found it!
Thank you again!
I forgot that I used ‘get_window().set_input_as_handled()’ in another gd file to ESC action! I deleted that and everything works!
Now I feel so stupid