matjlars / godot-multiplayer-input

This Godot addon provides two simple APIs for using normal Input Actions, but spread out across a Keyboard player and up to 8 Joypad players.
MIT License
104 stars 6 forks source link

Plugging in a controller crashes the game #6

Closed willerxxmiller closed 6 months ago

willerxxmiller commented 9 months ago

If I plug in a controller in my joinable scene, the game crashes.

`## Returns the name of a gamepad-specific action func get_action_name(device: int, action: StringName) -> StringName: if device >= 0: assert(device_actions.has(device), "Device %s has no actions. Maybe the joypad is disconnected." % device)

if it says this dictionary doesn't have the key,

    # that could mean it's an invalid action name.
    # or it could mean that action doesn't have a joypad event assigned
    return device_actions[device][action]

# return the normal action name for the keyboard player
return action`

The game crashes on the assert(device_actions.has(device), "Device %s has no actions. Maybe the joypad is disconnected." % device)

with an error of "Assertion failed: Device 1 has no actions. Maybe the joypad is disconnected".

I think when I plug the controller in, it triggers the "join" action before the action can be created from the "_on_joy_connection_changed".

willerxxmiller commented 9 months ago

changing the assert to: if(device_actions.has(device)):

seems to fix it

matjlars commented 9 months ago

hmmm I think that assert should still be there because it is a safeguard to protect me against myself. I do see my comment below that assert line and I'm wondering if any of those situations is what is happening to you?

Things to check:

  1. Typo in the action name?
  2. Does the action have a joypad event assigned to it in Project Settings -> Input Map?

If neither of those work, can you try testing your hypothesis by putting print statements at the very top of the _create_actions_for_device method to see if that gets called before the assert fails?

matjlars commented 6 months ago

Closing to clean it up. Feel free to re-open or create a new issue if you still need some help :)