godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.15k stars 96 forks source link

Add `Node.input_map_override` property #4774

Open me2beats opened 2 years ago

me2beats commented 2 years ago

Describe the project you are working on

a 3D game

Describe the problem or limitation you are having in your project

  1. I test different FPS templates in my project, for example AssetLib templates. A problem I can see is what often in these templates there is a code in _physics_process and _input() like is_action_pressed("action_name") that requires to manually add actions and bindings which is not handy, I would say even a bit annoying to add them, then if you don't find the template useful, delete them etc. The list of actions used in a template may be quite big.

  2. Another problem is sets of actions with overlapping events. If you have different types of movement in the game like

    • run
    • drive a car
    • drive a helicopter

then you can see that actions are different but some events overlap for example Key S:

And if you have all 3 actions (run, drive a car, drive a helicopter) in the InputMap, they all will be emitted/triggered, which means you need to do extra if else checks (like "if the player is running"). Or you can add/remove actions and events from the code, which is not handy.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

I suggest adding Node.input_map_override property. Any node added in the game will automatically add actions and their events (keystrokes, mouse clicks etc) defined in that property, to InputMap. And the actions can be also automatically removed when the node exits the tree (there can be an option for not doing that, see below).

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Say I create a node KinematicBody, then I write some code, for example for FPS movement, then I go to Inspector and set input_map_override property - I just add the actions like move_forward, move_backwards, move_left, move_right, jump, reload, interact etc and add events like keystrokes WASD. The I run the game and I have these actions added to InputMap (default actions and actions defined earlier ofc remain).

If this enhancement will not be used often, can it be worked around with a few lines of script?

you can solve [2] (overlapping events), but not [1] (a need to manually add actions and bindings for many nodes added from AssetLib or other places). Actually [1] cannot be solved completely, some asset/template creators will ignore the feature anyway. But I still think this feature would be used often.

Is there a reason why this should be core and not an add-on in the asset library?

I think having it as an add-on will be quite hacky, and still, this wouldn't solve problem [1]

me2beats commented 2 years ago

see also https://github.com/godotengine/godot-proposals/issues/2273

me2beats commented 2 years ago

Just a simple example: I needed to copy a character from one project to another. I copied the scene. But then I also had to copy-paste input actions and events. I solved it by copy-pasting [input] section in project.godot. I closed the project first to avoid conflicts. this is not so handy. And the case was easy, it would be harder if I would need to copy only several actions to a project that already has something in [input] section

Having a proposed feature implemented, I could just copy the scene, and input events would appear in the new project automatically (if the character scene node has input_map_override