Example of code needed - Using 2 xbox controllers with diffrent prefabs

Hi all.
Im making a fun learning game for my boys when each player control 1 character.
when im working with 1 joystick and 1 keyboard all is working great, but when i want to set up a 2nd xbox controller(instead of keyboard) i just cant get it to work.
i saw each xbox controller have a diffrent Device ID - is there a code i can use to read it on script?
Alternatively i tried to use the player Input manager, but i can only use 1 prefab and i want each player to have a diffrent character.

please advice.

Either switch the two instances in the scene explicitly during OnEnable:

player1.SwitchCurrentControlScheme("Gamepad", gamepad1);
player2.SwitchCurrentControlScheme("Gamepad", gamepad2);

Or instantiate them like this:

PlayerInput.Instantiate(prefab1, pairWithDevice: gamepad1);
PlayerInput.Instantiate(prefab2, pairWithDevice: gamepad2);
1 Like