0 votes

In my two player project, I want to have two separate upgrade screens, one for each player. The menus are up at the same time, and a player should only be able to interact with their own respective menu. I'm having a lot of difficulties making it happen since only one item can be in focus at a time (at least that I'm aware of).

asked Jun 21 in Engine by TheJollyReaper (56 points)

1 Answer

+1 vote
Best answer

Just set the "Focus Mode" to "None" and do the input handling yourself via the _input- or _unhandled_input-functions covered in greater detail here.

Here's a very simple example tree:

- GUI (Node-Type: Control)
  -  ButtonA (Node-Type: Button, Focus Mode = None)
  -  ButtonB (Node-Type: Button, Focus Mode = None)

Then your GUI.gd-script could look like this:

extends Control

func _input(event):
    if event is InputEventKey and event.pressed:
        match event.scancode:
            KEY_A:
                $ButtonA.emit_signal("pressed")
            KEY_B:
                $ButtonB.emit_signal("pressed")

func _on_ButtonA_pressed() -> void:
    print("A")

func _on_ButtonB_pressed() -> void:
    print("B")

When you now run the game, you can press the A-key to activate ButtonA and print "A", the B-key to activate ButtonB and print "B" or both at the same time.

answered Jun 22 by njamster (8,904 points)
selected Jun 22 by TheJollyReaper

I hadn't thought about assigning each button it's own key, I was focused (hah) on finding some way on being able to switch which button is being selected with a d-pad/joystick.

This works though! Might have to assign a key to toggle multiple menu screens, or to toggle which set of buttons is accepting requests at a time.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.