Search Unity

PlayerInput loses paired devices when actions are changed at runtime

Discussion in 'Input System' started by Heimlink, Nov 3, 2019.

  1. Heimlink

    Heimlink

    Joined:
    Feb 17, 2015
    Posts:
    29
    I have multiple scenes in my project, with a persistent GameObject that houses a list of children, each with a PlayerInput component, for a multiplayer game.

    In my first scene, I use the PlayerInputManager to allow the players to join the game. Which works fine. Each PlayerInput component lists the correct device.

    When all players are ready, I load my game scene, where I update the actions property on each of the PlayerInput components. When I do this, the PlayerInput unpairs from its devices.

    e.g.
    playerInput.actions = Instantiate(gameActions);

    I can see where this is happening in PlayerInput#AssignUserAndDevices. However, I'm not sure how to retain the paired devices when changing the actions.

    Using 1.0.0-preview.1 in Unity 2019.2.10
     
    Last edited: Nov 3, 2019
  2. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    that's not how you switch actions at all, why are you instancing something ?

    on playerInput (or playerInput.user I don't remember) there is a function called SwitchActionMap or something like that
     
  3. Heimlink

    Heimlink

    Joined:
    Feb 17, 2015
    Posts:
    29
    I'm trying to switch the Action in the PlayerInput; As opposed to switching Maps within an action.

    I have an asset for my Player Select screen, then an asset for my Game Play screen. Each contain their own set of maps. When I load the Game Play scene, I am updating the actions on my PlayerInput components to use the Game Play action asset.

    I need to Instantiate the action asset to create a private copy (see comments), as my game is multiplayer, each PlayerInput needs a clone of the asset.

    I could contain all my maps in a single asset, but I expect I should be able to switch Assets as well. I like to categorise my maps within assets.
     
  4. Heimlink

    Heimlink

    Joined:
    Feb 17, 2015
    Posts:
    29
    Problem is still present in 1.0.0-preview.2.
    @Rene-Damm I expect this is not the expected behaviour?

    I've worked around it for now, by simply re-pairing the devices with the following code:

    Code (CSharp):
    1. var devices = playerInput.devices.ToArray();
    2.  
    3. playerInput.actions = Instantiate(gameActions);
    4.  
    5. foreach (var d in devices)
    6.     InputUser.PerformPairingWithDevice(d, playerInput.user);