godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.89k stars 21.04k forks source link

GDExtension. The InputMap action doesn't exist #74993

Open Mr-SkyLark opened 1 year ago

Mr-SkyLark commented 1 year ago

Godot version

4.0.stable.official 4.0.2.stable.official

System information

Windows 10

Issue description

Output log sends many messages: The InputMap action "move_up" doesn't exist. Did you mean "ui_up"? But Godot knows and finds action. 2023-03-16_20-21-43

Steps to reproduce

2023-03-16_20-22-10

project.godot

...
[input]

move_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
]
}
...

Player.cpp

void Player::_process(float p_delta)
{
  Vector2 velocity(0, 0);

  velocity.x = _player_input->get_action_strength("move_right") - _player_input->get_action_strength("move_left");
  velocity.y = _player_input->get_action_strength("move_down") - _player_input->get_action_strength("move_up");
  Vector2 position = get_position();
  position += velocity * (real_t)p_delta;
  set_position(position);
}

Minimal reproduction project

bug_gdextension.zip

dodgyville commented 1 year ago

Also getting this on 4.0.1-rc1

Ethosa commented 1 year ago

Errors reproduce on 4.0.1

Calinou commented 1 year ago

@Mr-SkyLark Please upload a minimal reproduction project to make this easier to troubleshoot. (The project.godot and Player.cpp files make it possible to reproduce this locally, but it requires a lot of manual setup which not everyone has time for.)

@dodgyville @Ethosa Are you reproducing this with a GDExtension? If not, this is an unrelated issue.

Mr-SkyLark commented 1 year ago

@Calinou I have updated my report. I added ZIP file with minimum reproduction project. It contains C++ project and ready dll in the godot project.

jacogasp commented 1 year ago

Hello, I'm facing the same issue. I configured a custom input map in project settings and referenced it in the GDExtension C++ code. The input map actually works, which means that input is trigged by pressing the according key button, but the The InputMap action "move_up" doesn't exist. Did you mean "ui_up"? is printed at each frame in the Output log, even in editing mode

nvanfleet commented 1 year ago

I have this issue but the user input doesn't actually work and I get the spamming errors.

jacogasp commented 1 year ago

Hi @nvanfleet, in my experience if you correctly set the input map in the project settings, you should have no issue at runtime (playmode). Since GDExtension is loaded when editor starts, and the _process function is called per each frame, it seems to me that the editor loads the GDExtension before the input map configuration. Indeed, if you use one of the default action like ui_up, you have a moving player also in editor. This proves that the input map is simply loaded later.

As workaround, you can use this is snippet

#include <godot_cpp/classes/engine.hpp>

void Player::_process(float delta) {
  if (Engine::get_singleton()->is_editor_hint()) return; // Early return if we are in editor

  auto input = Input::get_singleton();
  if (input->is_action_pressed("move_up")) {
  // do stuff
  }
}

Sadly, using the Engine singleton is know to produce a memory leak and crash when exiting the game. https://github.com/godotengine/godot-cpp/issues/889

tsmuse commented 1 year ago

I have just started getting this same issue on a project I haven't touched in a week or so. Godot 3.5.2 using GDScript. It wasn't doing this the last time I worked on it, and as far as I can tell nothing has changed (git shows no files changed from my last commit). The InputMap actions are showing up in my project settings, and they all seem to work. The editor starts complaining as soon as I load the scene, and if I comment out the three lines that reference those custom input mappings, save the attached script, close the scene, then reopen it the warnings stop. If I close Godot and reopen it the errors come back until I run through the process again.

saierXP commented 9 months ago

My newbie friend has encountered this problem in gdscript, and I don't think the current way of handling it is appropriate and gives enough information.

This should be the same as the problem with gdscript in tool mode, which is caused by the editor itself not using the project custom InputMap.

There are no plans to have the editor load the project InputMap, but could we stop the spamming and then just output a warning telling the user not to use the InputMap in the editor. Of course we can also add a placeholder Action inside the editor using InputMap.add_action("action") to stop spamming.

GDScript issue:

kraasch commented 6 months ago

...but could we stop the spamming and then just output a warning telling the user not to use the InputMap in the editor.

Great idea.

kraasch commented 6 months ago

I have just started getting this same issue on a project I haven't touched in a week or so.

Same for me, on Godot 4.1.1

kraasch commented 6 months ago

What fixed it for me was to remove the @tool from script in which I checked for the InputMap, then I closed Godot and then I deleted the .godot directory in the project to make sure no cached references remained. Afterwards worked again fine! :smiling_face_with_tear:

tijanirf commented 3 months ago

For workaround, you can call InputMap.load_from_project_settings() inside _ready() function

Garmichael commented 1 month ago

For workaround, you can call InputMap.load_from_project_settings() inside _ready() function

When I do this, I get the custom action to work, but then it throws a bunch of errors about the various FreeLook inputs:

The InputMap action "spatial_editor/freelook_forward" doesn't exist.