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
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
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.
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:
var devices = playerInput.devices.ToArray();
playerInput.actions = Instantiate(gameActions);
foreach (var d in devices)
InputUser.PerformPairingWithDevice(d, playerInput.user);