The basic idea is to divide the player by device, or even to divide the player within a single input device.
For example, separate players input WASD and Arrow keys on the keyboard.
I have created a scheme called WASD and Arrow,GamePad. Then the following code is going to generate a player and set up the scheme and device.
However, once I run PlayerInput.Instantiate, the joinAction of the other device stops responding.
[SerializeField] InputActionReference joinAction;
[SerializeField] PlayerInput playerPrefab;
int currentPlayerCount;
void Start()
{
joinAction.action.Enable();
joinAction.action.performed += OnJoin;
}
private void OnDestroy()
{
joinAction.action.Dispose();
}
void OnJoin(InputAction.CallbackContext context)
{
InputDevice device = context.control.device;
string scheme = GetScheme(context.control);
PlayerInput.Instantiate(prefab: playerPrefab.gameObject,
playerIndex: currentPlayerCount,
controlScheme: scheme,
pairWithDevice: device);
currentPlayerCount++;
}
string GetScheme(InputControl control)
{
if (control.device is Gamepad) return "GamePad";
if (control.name == "space")
return "WASD";
if (control.name == "enter")
return "Arrow";
return "Unknown";
}```