Assign Input Device to Each Player Local Multiplayer Cinemachine New Input System

Is there a way to assign the input to each player?
What I’d like to do is have two players active in the scene on start, and have two controllers connected at start and have each controller assigned, one to each of the players.
The problem I’m having is that I’m using the new input system and a few cinemachine cameras are on each player. I’ve set up layers for the cameras and brains for each player, and have EventSystemMultiplayer for each player set up, and have a PlayerInputManager and I know that my player index assigns 0 to the first player and 1 to the second player, but the controllers both control a single player. Is there a way to assign the second player the second controller manually or by code or in some way. The normal way of doing this is to make a prefab and instantiate the prefab and the controller is automatically assigned to the controller when a button is pressed. I’d rather not do this, at least not until I get everything working correctly, such as assigning cameras to the weather system and other assets in my scenes.

What happened to the answer by Gorki1337? I can’t access the video either.

Answer from Gorki1337…
Yes, you can manually assign controllers to each player using the input system. To do this, first identify which controls (gamepad, keyboard, mouse, etc.) you want to assign to each player. For example, if you want the first player to use the first controller and the second player to use the second controller, note which controller corresponds to which player (index) within the input system.

You can also achieve this using a script. Here’s an example:

public PlayerInputManager playerInputManager;
public int playerIndex; // 0 is first and 1 is second player

private void Start()
{
Gamepad[ ] gamepads = Gamepad.all.ToArray();
InputDevice device = gamepads[playerIndex];
PlayerInput playerInput = playerInputManager.JoinPlayer(playerIndex, controlScheme: “Gamepad”, device);
// do something
}

If you don’t understand what I’m trying to say because it’s not very easy to explain through post, it’s best for you to watch the video.

I still can’t make this work nor do I understand the code enough to tweak it to my situation. If you can repost the video and explain what playerInputManager.JoinPlayer variables are supposed to come from or what they do and need to be I would appreciate it. I also can not access the vide if you could post that again too. Thanks.

Is there something else that has to be done when using cinemachine?

In CM3, things are a little more streamlined and we have a sample scene that demonstrates how to do this. If you’re willing to upgrade to CM3, that might be your best option.

Are you saying my options are to upgrade or not use Cinemachine? I saw some tutorials on how to use cinemachine with the new input system but I don’t understand what they are doing very well, and I am using 8 cinemachine cameras on each player so upgrading is also not my preferred solution. Would upgrading require resetting all of the cameras? Is there another option?

Probably should not recommend using Cinemachine if it doesn’t work with the input system and two players.

Updated to cinemachine3 in unity2022 but I can’t figure out what to do with the CustomInputHandler.cs script. If I put it on my player object that has the playerInput it changes it to use c# events but I’m set up to use BroadcastMessages. Is there any way around this or do I have to use c# events? Can I put it on each camera instead?

Got most of it working. One problem was that the camera was not following the player. This I found, was caused by the residual cinemachine objects that are created when cinemachine is automatically updated to the new cameras from cinemachine2. The brain was still referencing those and I reset the player targets to be what they should be in my scene. This helped. It would have been easier to find if the cameras in cinemachine3 showed which camera was live. Seems like that feature is not working. Another problem was that the output channel was not changing by the playerinitializer.cs, I don’t remember why but I fiddled with it and got the brain output channel to match all the camera inputchannel. I changed the script to use arrays for the cameras in the scene and also added an array for state driven cameras since there is a field for outputchannel and it also needs to match the brain outputchannel. I haven’t been able to get the custominputhandler.cs to work so the camera doesn’t look around yet, but i’m going to try to add it to each camera and disable the cinemachineinputaxiscontroller.cs and see it I can get that to work.

Both controllers control the same player. Do I need to put a CustomInputHandler.cs script on the gameobject that has the player controller? Do I need to use the simpleplayercontroller.cs script on my player. custominputhandler.cs seems to require it or it doesn’t work. Does this have anything to do with both controllers being assigned to the same player?

Is there way to just put four players in the scene and assign controllers/input to them and adjust the cameras and set them active when needed? Seems like this should be possible and easier, but the PlayerManager wants to instantiate them.

Seems like from the documentation you need to use the new input system using c# events. Is there a way to make multiple player with cinemachine work with other input system ways like Unity Events or in my case, broadcast messages?

Rewrote the input system to use c# events set my player up as close to the sample two player cinemachine scene that comes with cinemachine3. Just throwing shit at the wall now. Both controllers are immediatly assigned to one player when a second player joins. Not sure what assigns them or why they are assigned to one player. It doesn’t happen in the sample scene. Any help from the void, a tutorial, another sample, better commenting on the scripts would help.