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

Faulty InputMap action doesn't exist error message. #132

Closed
jiaxiongjiao opened this issue Feb 25, 2023 · 6 comments · Fixed by #365
Closed

Faulty InputMap action doesn't exist error message. #132

jiaxiongjiao opened this issue Feb 25, 2023 · 6 comments · Fixed by #365
Labels
bug c: engine Godot classes (nodes, resources, ...)

Comments

@jiaxiongjiao
Copy link

When adding

// let input = Input::singleton();
// -----
if input.is_action_pressed("my_own_action".into(), false) { 
    // actions
}
// -----

to process or physics_process in GodotExt trait. Godot would report this "my_own_action" does not exist. This is not true
because

  1. In Project Settings -> Input Map, "my_own_action" is indeed there.
  2. When I run the game, error messages disappear and godot can even perform corresponding action to "my_own_action" when I press the action's key.

This behaviour can be replicated on the example game.

  1. add a new action, for example, "print_action" with key "M Physical"
  2. In player.rs -> fn process, add
if input.is_action_pressed("print_action".into(), false) {
    prints("print_action pressed!!!".to_variant(), &[]);
}

at the end of action checking
3. Build rust extension
4. Go to Godot and save project
5. The next time you open the project, the output section would keep printing the same red error messages over and over again
saying there is no such action when the game is not even running yet.

@Bromeon Bromeon added bug c: engine Godot classes (nodes, resources, ...) labels Feb 25, 2023
@lilizoey
Copy link
Member

i believe this is just a consequence of #70 so should be fixed when that is

@lilizoey
Copy link
Member

lilizoey commented Mar 3, 2023

Just to confirm my theory, i made a script

@tool extends Node2D

func _process(delta):
	if Input.is_action_just_pressed("asd"):
		pass

and added an action "asd" to the input map. It has the same behavior. So the issue is probably just that the code is running in the editor.

@atrefonas
Copy link

atrefonas commented Mar 7, 2023

I experienced the issue as well. The code is running in the editor for whatever reason. You can work around it by doing:

let input_map = InputMap::singleton();
if input_map.has_action("print_action".into()) {
  if input.is_action_pressed("print_action".into(), false) {
      prints("print_action pressed!!!".to_variant(), &[]);
  }
}

@lilizoey
Copy link
Member

lilizoey commented Mar 7, 2023

I experienced the issue as well. The code is running in the editor for whatever reason. You can work around it by doing:

let input_map = InputMap::singleton();
if input_map.has_action("print_action".into()) {
  if input.is_action_pressed("print_action".into(), false) {
      prints("print_action pressed!!!".to_variant(), &[]);
  }
}

There's also the usual workaround of doing Engine::singleton().is_editor_hint() to check whether the code is running the editor

@Bromeon
Copy link
Member

Bromeon commented Mar 7, 2023

The code is running in the editor for whatever reason.

That reason is called GDExtension 😉
See #70, also linked above.

@0x53A
Copy link
Contributor

0x53A commented Nov 3, 2024

I hit the same issue and found a solution:

InputMap.load_from_project_settings()

full credit to https://www.reddit.com/r/godot/comments/194l8dc/comment/khgv4hw/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug c: engine Godot classes (nodes, resources, ...)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants