Search Unity

Question Possible to query "Unjoined Players" for "Press A to Join"?

Discussion in 'Input System' started by UnkelRambo, Jan 9, 2023.

  1. UnkelRambo

    UnkelRambo

    Joined:
    Oct 26, 2012
    Posts:
    80
    Hi! I've been digging into this for an hour or so and haven't really found a great way to do this, but I was wondering if there's a simple way to query the Input System for POSSIBLE players who have a device connected but haven't joined yet?

    Something like this (not my game):


    The path I'm going down (which I really don't like for a number of reasons) is to check the InputDevices.devices for "usable" devices. There's a small bit of complexity here (handling keyboard/mouse as 1 possible player, each controller as 1 possible player, etc) which isn't too bad so far, but there ARE some funky edge cases I'm running into that are a pain.

    For instance, handling keyboard/mouse focus happens in two separate events when InputSystem.onDeviceChange fires. I want to do some special logic when a device is lost/reset/etc, and the logic in here to handle "the mouse was reset but NOT the keyboard" (when a wireless mouse dies, for instance) is REALLY gross (and so far, super error prone!)

    All I'm really trying to do is make a robust input handling for 3 scenarios:

    1. There's a controller connected but that player has NOT joined (to show the "Press X to Join"
    2. A controller is plugged in/unplugged/loses battery/etc at runtime.
    3. Players can use keyboard+mouse or a gamepad for input, that's it.

    Any and all suggestions appreciated, thanks!