I’m putting an EditorPlugin together that I want to provide the user with some default input mappings for a pair of controllers. I have adding actions to the InputMap already set up, but I was hoping to also have these new actions show up in the “Input Map” tab of the “Project Settings” window. What do I need to do in my EditorPlugin script to get these new actions to show?
@tool
extends EditorScript
func _run() -> void:
# Create the input events
var event_key = InputEventKey.new()
event_key.physical_keycode = KEY_R
var event_joypad = InputEventJoypadButton.new()
event_joypad.button_index = JOY_BUTTON_X
# Create the input dictionary
var input = {
"deadzone": 0.5,
"events": [
event_key,
event_joypad
]
}
# Set the input/<name_of_your_input_action> in the project settings
ProjectSettings.set_setting('input/reload', input)
# Save them
ProjectSettings.save()
# I've not found a way to update the project settings input map editor
# but to restart the whole editor.
#EditorInterface.restart_editor(true)
I’m using an EditorScript but the same can be done with a plugin.
I just hit the same problem and saw this in the documentation for InputMap.action_get_events():
Note: When used in the editor (e.g. a tool script or EditorPlugin), this method will return events for the editor action. If you want to access your project’s input binds from the editor, read the input/* settings from ProjectSettings.
I haven’t seen that stated explicitly elsewhere in the docs… but I ran into it within an hour, so
Just posting this here in case someone else runs into this weird issue while messing with InputMap and plugins:
I noticed while working on this plugin that suddenly my controller was manipulating the editor. This was due to my adding InputMap.load_from_project_settings() after adding all my custom input actions and events from the plugin. My thinking was this would help get the actions to show immediately in the Input Map tab of Project Settings (it didn’t). Not sure what the use of load_from_project_settings() is then, but hopefully this helps save someone the two hour headache it just caused me, lol.