This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hey guys, loving Godot so far but got stumped. So far I only know of ways to check if a player input is mapped to a specific action.
Is there a way to check if a player input is mapped to any action in general and not just one?

in Engine by (15 points)

1 Answer

+2 votes
Best answer

You can probably just set up a mapping yourself. Try maybe something like this:

var map = {}

func _ready():
    set_up_action_map()

func set_up_action_map():
    for action in InputMap.get_actions():
        for input in InputMap.get_action_list(action):
            if input is InputEventKey:
                map[input.scancode] = action
    print(map)

This will give you something like:

{
    <scancode_1>: 'ui_down',
    <scancode_2>: 'ui_left',
}

where <scancode_*> is the scancode for the key press input.

then, you can just check if a scancode exists in the map to see if that key is assigned to an action.

by (1,663 points)
selected by

Works just as you said, thanks!

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.