Problem with _Input() function which somehow ignores ESC actions

Godot Version

GODOT 4.3

Question

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”)

1 Like

You need to set its mode to always, otherwise it will either never be displayed or will never be hidden

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)

1 Like

I use SLib for pausing. But I used to use this code to pause:

func _input(event):
	if event.is_action_pressed("ui_cancel"):
		get_tree().paused = !get_tree().paused
		$".".visible = !$".".visible
1 Like

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.

1 Like

before the _input function, maybe you handled the action somewhere?

No I didn’t. Actually this .gd file is pretty simple and no other Input function is envolved.

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.

maybe handled on other .gd file ?
you can try

Input.is_action_just_pressed("ESC")

if catch the event, but _input func not.
it must be handled.

1 Like

Well it did catch the event. So this means ESC action is handled before _input?
I’ll check if there is something wrong in other .gd files
Thank you!

1 Like

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 :frowning:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.