1
\$\begingroup\$

I have created a simple C++ "game" in godot. Lacking any good documentation, I based my work off examples on the internet, and for input I have this:

    const Input* i = Input::get_singleton();

    double delta_v = 0;
    if (i->is_action_pressed("ui_up"))
        delta_v += acceleration * delta;
    if (i->is_action_pressed("ui_down"))
        delta_v -= acceleration * delta;
    if (i->is_action_pressed("ui_left"))
        angular_velocity -= angular_acceleration * delta;
    if (i->is_action_pressed("ui_right"))
        angular_velocity += angular_acceleration * delta;

Based on that, I wanted to add a new action triggered by space. So I tried this:

    const Input* i = Input::get_singleton();
    if (i->is_action_pressed("game_shoot"))
    {
        
    }

I then added this action in the project key mapping:

enter image description here

But I am getting an error:

The InputMap action "game_shoot" doesn't exist.

Curiously, it works from a script like this:

func _input(event):
    if event.is_action_pressed("game_shoot"):
        print("game_shoot occurred!")
\$\endgroup\$
6
  • \$\begingroup\$ How have you configured your Input Map, as described in the documentation here? \$\endgroup\$
    – DMGregory
    Oct 16, 2022 at 13:46
  • \$\begingroup\$ @DMGregory Not really, thanks for the link. But if configuration is required, how come the arrows work out of the box? \$\endgroup\$ Oct 16, 2022 at 13:50
  • 1
    \$\begingroup\$ I'd guess because they're pre-configured as commonly-used defaults? I've never used Godot, but Unity does something similar with both the legacy Input Manager and the new Input System package. \$\endgroup\$
    – DMGregory
    Oct 16, 2022 at 13:52
  • \$\begingroup\$ @DMGregory Thanks, I understand now. However adding new action, such as game_shoot does not seem to work. I am still getting the same error when I try to query it from the C++ side. \$\endgroup\$ Oct 16, 2022 at 13:55
  • \$\begingroup\$ Make sure you edit your question to show your updated configuration and code. \$\endgroup\$
    – DMGregory
    Oct 16, 2022 at 13:57

1 Answer 1

1
\$\begingroup\$

I finally figured this out. There is a method on the InputMap singleton. You probably should call this only once.

    InputMap* map = InputMap::get_singleton();
    map->load_from_project_settings();
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .