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

Unique Input Device ID #10349

Open
PerfectlyFineCode opened this issue Aug 3, 2024 · 2 comments
Open

Unique Input Device ID #10349

PerfectlyFineCode opened this issue Aug 3, 2024 · 2 comments

Comments

@PerfectlyFineCode
Copy link

PerfectlyFineCode commented Aug 3, 2024

Describe the project you are working on

A local co-op game which allows you to control each player, 3D isometric roguelite.

Describe the problem or limitation you are having in your project

Current solution requires either checking what input type is being pressed and adding a tag of it's ID by the device type. So that each input device has a unique ID.

Or as others have mentioned, making multiple input maps for each player which is troublesome and just annoying.

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

The feature in question would be to have a way of distinguishing between each input device by a unique ID.
This would help local co-op games.

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

# Array containing the bound devices per player.
var bound_devices: Array[int] = [ ]

### Check if the device is bound
func has_device(id: int) -> bool:
    for device: int in bound_devices:
         if device == id:
             return true
    return false

func _unhandled_input(event: InputEvent) -> void:
  # event.device should return a unique ID for that input device
  if !has_device(event.device): # Check if the device is not bound
        return # Ignore input if it isn't bound
  if event.is_action_pressed("jump", event.device): # or can even check whether action is pressed on a per-device basis.
      print("Jump is pressed for device ", event.device)
   

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

Current solution requires either checking what input type is being pressed and adding a tag of it's ID by the device type. So that each input device has a unique ID. Or by making multiple input maps for each player which is troublesome and just annoying.

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

This should be a core feature that improves the Engine as a whole and can lead to significantly easier making local co-op without having to waste time on making a whole system or duplicating input maps per player.

@AThousandShips
Copy link
Member

Note that the suggested syntax would break compatibility, as we can't add an argument in the middle of the arguments

The input does track some device info internally, but it doesn't track time individually so it would have to be changed with more timing info for this to work, or you couldn't use is_action_just_pressed etc.

Generally the method for this would be to create individual actions with suffixes for each device, and then configure each player's code to reference the correct index, I would say that it might be more reasonable to make it easier to configure multi input systems with some form of automated tool in the input map instead

An alternative method would be to reconfigure the input map when players are linked to individual devices, that way you can use the classic "press any button to join as player 2" can be worked out by detecting the device and linking just all those actions, a bit more complicated but could be made easier with some helper code

@Calinou
Copy link
Member

Calinou commented Aug 3, 2024

Note that there are are already multiple proposals aiming to address the same problem:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants