I am doing some exploatory programming for a local multiplayer project.
I want the player to connect, select an avatar and then that avatar comes with a specific control scheme. This avatar should be re-selected if the player re-connects.
I would like to create several InputAction assets and switch between them, according to the player choice.
What would be the reasonable way to create the multi-controller setup architecture using the Input System features? I am mostly concerned about assigning controllers and switching the input actions: should I go switching action maps instead?
1 Like
I don’t know much about this but you should take a look at this.
There is a method in PlayerInput called
SwitchCurrentControlScheme(String, InputDevice[ ])
it can switch between Control Schemes that you’ve created. So you could have one input actions and create several different Schemes and switch between them using whatever logic you’d need.
Here’s a link to the documentation I read where it mentions this:
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.PlayerInput.html#UnityEngine_InputSystem_PlayerInput_SwitchCurrentControlScheme_System_String_UnityEngine_InputSystem_InputDevice___
For more explanation on the function it should be at the top of the document.
Hope that helps
1 Like
Thank you.
My current plan is to use PlayerInput as the component that handles the player for each of the avatars, then use a component and a central component which instantiates the avatar prefab and handles its lifetime.
My two current conundrums are:
- device serials seem to be empty strings for both xbox one and ps4 controller
- cannot cleanly detect both reconnection and adding, as adding event always fires and reconnection fires after that one. it doesn’t help that the controller gets a new internal id on each connection
EDIT: after some reading it’s apparent that persistent IDs for controllers are practically impossible and thus I will likely just drop the feature that lets you reconnect without a hassle
if its about having the player join and leave then perhaps take a look at player input manager component. That is basically what it does. Though its features at the moment are a bit limited from what I know but I haven’t looked into it that much.