My InputActions asset is setup like this using 2 control schemes “KeyboardP1” and “KeyboardP2”:
Then I have a PlayerInputLogger prefab with a PlayerInput component using my PlayerInputActions asset and my PlayerInputLogger component:
Here’s the code for PlayerInputLogger component:
public class PlayerInputsLogger : MonoBehaviour {
public InputActionReference Action1;
void Start() {
Action1.action.performed += _ => Debug.Log("Action 1 performed");
}
}
Then, I have PlayerInputsSpawner object and the component in the test scene. Here’s the code for PlayerInputsSpawner component:
public class PlayerInputsSpawner : MonoBehaviour {
public GameObject PlayerInputLogger;
void Start() {
PlayerInput Player1 = PlayerInput.Instantiate(PlayerInputLogger, controlScheme: "KeyboardP1", pairWithDevice: Keyboard.current);
PlayerInput Player2 = PlayerInput.Instantiate(PlayerInputLogger, controlScheme: "KeyboardP2", pairWithDevice: Keyboard.current);
}
}
When I start the game, here’s how the scene looks like:
It logs only when I press on the G key and not Numpad1 key. When I switch the control schemes on the spawned objects, so that the first instantiated object uses KeyboardP2 control scheme, it logs when I press numpad1 key but not the G key. Only the first instantiated object is working.
I’m trying to do it this way, because it was recommended to do it this way in those threads: 2 Players on same input device
Multiple players on Keyboard (New Input system) - #25 by katecobey
But it doesn’t work. Any advice?