How do I give an object an InputUser to listen to?

Hello!

I have some cursor objects in a character select screen for a local multiplayer game. The cursors each have a player input component and I am instantiating them from a manager script. In a previous scene, I have created inputUsers and bound devices to them. These inputUsers are also saved in a manager script.

Now when I instantiate the cursor objects, I want to have them only receive inputs from the devices paired to the created inputUser for each player, how would I go about this?

Pairing devices to input users:

public class ControllerBinding : MonoBehaviour
{
    [SerializeField] int playerToBind;
    InputUser[] playerUsers;

    List<InputDevice> pairedDevices = new();

    private void Start()
    {
        // Make the inputPlayer array the size of the amount of players
        playerUsers = new InputUser[Singleton.Instance.GameManager.PlayerAmount()];

        // Make sure the first player to bind is player 1
        playerToBind = 0;
    }

    // When a controller button is pressed
    public void ControllerPressed(InputAction.CallbackContext context)
    {
        // Save the device on which a button was pressed
        InputDevice controller = context.control.device;

        // If device is already paired, return
        if (pairedDevices.Contains(controller)) { return; }

        // Add controller to list of paired devices
        pairedDevices.Add(controller);

        // Depending on which player to bind to, bind the device to the InputUser
        InputUser.PerformPairingWithDevice(controller, playerUsers[playerToBind], InputUserPairingOptions.UnpairCurrentDevicesFromUser);

        // Set the playertobind to the next player
        playerToBind++;

        // If playertobind is above the amount of players, give inputUsers to manager and go to the next screen
        if (playerToBind +1 > Singleton.Instance.GameManager.PlayerAmount())
        {
            Singleton.Instance.GameManager.SetPlayerUsers(playerUsers);

            SceneManager.LoadScene(nextScene);
        }
    }
}

Any help or ideas would be much appreciated :slight_smile:

Found a solution by using the PlayerInput.Instantiate() function. I was simply able to give the instantiated prefab a device to pair with, without having to use an inputUser.

Here is the documentation for those curious :slight_smile: