Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputMap.get_action_list() doesn't return Joypad buttons when called in the editor #54950

Closed
FringeSci-com opened this issue Nov 13, 2021 · 7 comments · Fixed by #60731
Closed

Comments

@FringeSci-com
Copy link

Godot version

3.4.stable

System information

Windows 10

Issue description

When you call InputMap.get_action_list() in a tool script in the editor, it only returns keyboard buttons. Joypad buttons, axes, mouse buttons, and physical keyboard buttons don't show up. This only happens in the editor, when running the game it returns all the different types of controls as you'd expect.

I've tested this in 3.4 and 3.2.3 and they both have the same behavior.

(This has put a slight damper on my button prompt node that grabs button graphics based off of your Input Map. 😢)

Steps to reproduce

Create a Node2D with the following script:

tool
extends Node2D

func _init():
	print(InputMap.get_action_list("ui_accept"))

In the editor it will print:
[[InputEventKey:60], [InputEventKey:61], [InputEventKey:62]]
(The numbers might be different for you)

If you play the project it will print:
[[InputEventKey:20], [InputEventKey:21], [InputEventKey:22], [InputEventJoypadButton:23]]

Notice when running in the editor it's missing the InputEventJoypadButton, but when playing the project it outputs all the buttons as expected.

If you add Joypad Axes, Mouse Buttons, or Physical Keyboard Buttons to ui_accept, you'll find that they're also missing in the editor as well.

Minimal reproduction project

No response

@Calinou
Copy link
Member

Calinou commented Nov 13, 2021

From a quick look in 3.x's core/input_map.cpp, I can't see why non-key events would be specifically excluded.

@KoBeWi
Copy link
Member

KoBeWi commented Nov 13, 2021

Could be because in editor it uses editor actions (default) and at runtime it uses the input map from project settings?

@FringeSci-com
Copy link
Author

Could be because in editor it uses editor actions (default) and at runtime it uses the input map from project settings?

You might be on to something. Just tested this on a custom action and not one of the built-ins and it didn't show anything in the editor at all.

@akien-mga
Copy link
Member

I can't find where this would be implemented, but I think the editor ignores joypad input on purpose, due to #16832.

@madmiraal
Copy link
Contributor

madmiraal commented Dec 28, 2021

This is by design. Godot engine is a game; so it has its own, fixed InputMap which is loaded and used by the editor and the project manager:

godot/main/main.cpp

Lines 1257 to 1263 in 28174d5

if (editor || project_manager) {
Engine::get_singleton()->set_editor_hint(true);
use_custom_res = false;
input_map->load_default(); //keys for editor
} else {
input_map->load_from_project_settings(); //keys for game
}

When you call InputMap.get_action_list("ui_accept") (or InputMap.action_get_events("ui_accept") in 4.0) within the editor you get the editor's InputMap, which is limited to those key mappings.
To get the project's InputMap's Action's events, you need to use ProjectSettings.get_setting("input/ui_accept").events.

@Zireael07
Copy link
Contributor

@madmiraal Is this documented anywhere?

@madmiraal
Copy link
Contributor

Is this documented anywhere?

Not that I know of.

@Calinou Calinou added documentation and removed bug labels Dec 28, 2021
@Calinou Calinou added this to the 4.0 milestone Dec 28, 2021
@KoBeWi KoBeWi moved this to Todo in 4.x Priority Issues May 1, 2022
@akien-mga akien-mga modified the milestones: 4.0, 3.5 May 3, 2022
Repository owner moved this from Todo to Done in 4.x Priority Issues May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants