Search Unity

Question XBOX platform: 4 controllers plugged: filtering input so that it ignores all controllers but one

Discussion in 'Input System' started by NeatWolf, May 26, 2021.

  1. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    Hi there!

    I'm using Preview3 of the IS on PC+XBOX

    Filtering input from a single controller (and ignoring the other 3) seems to be something trivial, but I'm probably doing something wrong. Or, it's right in front of my eyes and I have 2 big hams on them.

    I currently am on a PC+XBOX project, and -I confess-, I turned up my nose when thinking about using 3rd party solutions such as Rewired.

    Fact is: it's pretty late, and almost all project (a single player only project) has been getting all input via ActionMaps, but NOT using PlayerInput - which initially felt a bit overkill, and with plenty of unused features I didn't need.

    Now Unity seems to suggest hooking up an InputUser to PlayerInput.

    All I currently have is an InputActionAsset with different ActionMaps (depending on the game internal logic - an actionmap for the UI, one for moving the player, etc.) that I manually enable/disable when appropriate.
    I'm using the auto-generated GameControls partial class (
    auto-generated by com.unity.inputsystem:InputActionCodeGenerator)
    , which can be referenced everywhere via a persistent singleton GameControlsManager

    I was hoping to find a field that let me filter all gamepad input from a single source, but instead I have 4 gamepads which could control the same player.
    And that's not so good on XBOX - pretty sure Microsoft isn't going to like that :p

    I also have some partial wrapper of the input, so I -could- refactor most things if I could retrieve from each InputAction the InputUser/PlayerInput it's coming from.

    Fact is, I'm a bit clueless about how to do that, and it's very specific.

    I couldn't find any code snippet to do that, and the docs seem to be a bit generic.

    Could you please point me in the right direction or share any suggestion?
     
    Last edited: May 26, 2021
  2. robinlloydmiller

    robinlloydmiller

    Joined:
    Oct 24, 2019
    Posts:
    9
  3. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    There are several ways to deal with that kind of filtering.

    At the top level, the Input System has an implementation called PlayerInput which is pretty much an example of how to deal with local-multiplayer stuff.

    Under the hood, PlayerInput enforces device binding/pairing by ensuring it creates a new InputUser that only listens to specific devices.

    It's worth mentioning that things like PlayerInput and the Generate C# checkbox are effectively *alternatives* to eachother and do not mesh well.