#Controlling Pause UI with Gamepad

47 messages · Page 1 of 1 (latest)

sharp elm
#

Hey, I'm trying to get my game to recognize input from the gamepad so I can choose options and press buttons in a pause menu.
The setup is relatively simple. The UI consists of a resume and quit button. See the attached screenshots.
The player script calls the pause function of the pause UI script using unhandled input. I have tried a few things, but I have no idea how to get the menu to recognize gamepad inputs other than moving up and down with the D-Pad.

SOLUTION: #1096307775543463947 message

Discord

Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

#

I have a shortcut setup on the resume button to listen for the pause input event which I have mapped to esc on keyboard and pause on the gamepad. I thought about making a shortcut for the quit button, but that wouldn't work as desired as each time I press the button it would quit the game instead of pressing whichever button has focus.

icy lagoon
#

change the input maps ui-left, ui-up and other functions

#

and you want to use a input map action

#

use a process function, and do is Input.is_action_just_pressed("pause")

sharp elm
#

And I already have a working function that listens for the pause:

icy lagoon
#

you want the resume button to trigger the unpause event?

#

you can use Input.parse_input_event

#

however, why dont you just connect the pressed signal to unpause?

sharp elm
icy lagoon
#

what is ui_accept?

sharp elm
#

By default it is spacebar and in addition I mapped the A button on the gamepad

#

The pause menu accepts the space button when on the menu, along with the enter key, but it doesn’t accept the A button on the gamepad. But I can use the gamepad dpad buttons to change the focused button, which is what I want. I just can’t use the gamepad to press the focused button.

#

I can maybe make a video if it’s easier to understand

icy lagoon
#

if you press enter on the keyboard does it work?

sharp elm
sharp elm
#

I wonder if it’s an issue where gamepad is being ignored because the tree is paused.

#

Idk

icy lagoon
#

do the _input functions register the gamepad?

sharp elm
#

I believe they do when the tree is not paused but I’ll have to double check to see if they do when the tree is paused

sharp elm
#

So, I checked, the jump button doesn't register when the tree is paused.

#

How can I fix this?

#

It seems that setting the players process mode to always allows for calling input functions, now to hook it up to the UI, hope this works.

sharp elm
#

Okay, so I've run into a couple of problems here:
First: I don't know how to get the ui to press the focused button when I hit the jump/ui_accept input
Second: Now that I have set the player process mode to always, even though everything else is paused the player can still look around, I don't want this.

icy lagoon
#

interesting, so because _input doesnt work in paused games, the buttons dont work with gamepad input?

#

that sounds like a bug, as keyboard input does work

sharp elm
#

I just have to figure out how to get Godot to also recognize the gamepad input as ui_accept

icy lagoon
#

nope thats definetly a bug

#

if your not going to report it, ill see if i can repro myself

sharp elm
#

That's all well and good if you want to do that, but this is getting off-topic for the thread. I'm trying to get Godot to recognize a gamepad button press as ui_accept, since ui inputs are recognized when the Scene Tree is paused (since my pause menu has process mode set to always).

desert sky
#

Go to the input map, enable Show Built-in Actions, then add the gamepad button you want to the ui_accept action

sharp elm
#

Sweet, menu is working with gamepad

#

and keyboard

#

Solution:

Make sure the Input Map is set properly to the keys you expect to press. Built in actions (ui_ actions) are hidden by default. Make sure to toggle "Show Built-in Actions" See screenshot. (Bottom of post)

  • On Player Script:
    if event.is_action_pressed("pause"):
        $PauseMenu.pause()```

- On Pause Menu Script (**Pause Menu process mode must be set to "Always" in the inspector**):
```extends ColorRect

@onready var animator: AnimationPlayer = $AnimationPlayer
@onready var Resume: Button = find_child("BTN_Resume")
@onready var Quit: Button = find_child("BTN_Quit")


func unpause():
    animator.play("Unpause")
    get_tree().paused = false
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)


func pause():
    animator.play("Pause")
    get_tree().paused = true
    Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
    Resume.grab_focus()


func quit():
    get_tree().quit()


func _ready() -> void:
    Resume.pressed.connect(unpause)
    Quit.pressed.connect(quit)```
#

Seems Resume.grab_focus() is important because if I comment that out, nothing has focus by default and I can't change the focus.

icy lagoon
sharp elm
# icy lagoon you said so here

I was mistaken. What I did was create a mapping for "jump" set to space and the A button on the gamepad, then mapped it in code, because I didn't see that the built-in actions were hidden by default.

icy lagoon
#

._.

#

.__________.