Button Input on pause

I got a stack overflow. it says I should check the infinite recursion which I guess is the function you showed me

Stack overflow (stack size: 1024). Check for infinite recursion in your script.

extends SubViewport


func _input(event: InputEvent) -> void:
	push_input(event)

I haven’t looked very closely but if you use tweens to animate the buttons I believe the problem could be with the them. They need to have their process mode set separately. They will not inherit the process mode from the whatever node creates them.

tween.set_pause_mode(Tween.TWEEN_PAUSE_PROCESS)

If you have infinite recursion, are you sure that your input is not used to 1. open the pause menu, 2. press the continue button, 3. open the pause menu again etc etc? Especially if it is the continue button that spawns in focused.

Could you try call_deferred the grab_focus() of the button?

the resum buttoj is suppossed to be focused when paused, but it’s not focused, there is just no Input

Oh you keep it invisible then toggle on and off? So not a ready.

In that case connect the grab focus function to the visibility changed signal or the root node toggled visible/invisible. If toggled on, grab focus.

Making something visible or kinvisible back and forth messes with the focus in my experience.

no, it’s always visible. What I said is that when the scene tree isnt paused, then it works perfectly fine, else? it doesnt work. If you want more details, please check my precious comments

Interesting. I called it from a parent class. I thought that was overly complex, so I tried to simplify it for you. However, it seems you have to, because otherwise you get infinite recursion.

  1. Delete that script.
  2. Right-click on the SubViewport and select %Access as Unique Name
  3. Add a script to Main:
@onready var sub_viewport: SubViewport = %SubViewport


func _input(event: InputEvent) -> void:
	sub_viewport.push_input(event)

that didnt work

After 4 days, I finally fixed it and for those who have the same issue this is what I did:

So first of all, if you have a custom node because you are using a class, then the extended script’s input will run if it’s paused (only if process_mode == ALWAYS or When Paused). but the class script itself will also be able to run, but not it’s Input, so what I did is add a custom node/class which was Navigation for me, I didnt extend any script to it so it’s input could run. I added an export variable called nav_node which when a button is pressed, a signal/function will be called to the nav_node so no extended scripts are needed and then in the nav_node (Which is just a panel) will get the function and do what it has to do