Search Unity

New Input Manager Split Screen and Cinemachine

Discussion in 'Input System' started by Northmaen, Jan 17, 2020.

  1. Northmaen

    Northmaen

    Joined:
    Jun 23, 2015
    Posts:
    17
    Hi there,

    I'm trying to figure out how to combine the new input system manager (with split screen enabled) and Cinemachine.

    I linked a camera and a virtual camera in the player prefab, its hierarchy looks like this :

    PlayerHolder
    -- Player
    -- PlayerCamera
    -- PlayerVirtualCamera

    When the first player joins in, everything is fine, but as soon a the second one enters the game, the virtual camera pans to the second player on both screens.

    Is Cinemachine compatible with the new input system? I know that Cinemachine works with split screen, as Unity made a Youtube tutorial about it:



    Anyone got it to work?
     
    Filip8429, bguyl and UnityAdam93 like this.
  2. UnityAdam93

    UnityAdam93

    Joined:
    Mar 5, 2017
    Posts:
    3
    I'm also trying to do a similar thing.
    Would be very interested in a solution for this!
     
  3. Northmaen

    Northmaen

    Joined:
    Jun 23, 2015
    Posts:
    17
    Hey! What I ended up doing is writing a setup script and change the VM cams and regular cams when a player is joining.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerManager : MonoBehaviour
    4. {
    5.     public Camera cam;
    6.     public GameObject virtualCam;
    7.  
    8.     public void Setup(int layer)
    9.     {
    10.         virtualCam.layer = layer;
    11.         var bitMask = (1 << layer)
    12.             | (1 << 0)
    13.             | (1 << 1)
    14.             | (1 << 2)
    15.             | (1 << 4)
    16.             | (1 << 5)
    17.             | (1 << 8);
    18.         cam.cullingMask = bitMask;
    19.         cam.gameObject.layer = layer;
    20.     }
    21. }
    I keep a List of PlayerInput somewhere in the app (in my case, in a scriptable object) hooked up to Player Input Manager's events, and assign layers based on their index in this list.
     

    Attached Files:

  4. Bkenkel

    Bkenkel

    Joined:
    Jun 17, 2019
    Posts:
    1
    At the moment, split-screen in Unity is not compatible with Cinemachine. I came across this post looking for a guide to local multiplayer in Unity and then accidentally found the answer to your problem in Unity's new input system documentation. Capture.PNG
     
  5. Northmaen

    Northmaen

    Joined:
    Jun 23, 2015
    Posts:
    17
    It's not plug and play but we can make it work with a little bit of code, see my answer above.
     
    DavidVoid likes this.
  6. MarNevGames

    MarNevGames

    Joined:
    Feb 1, 2016
    Posts:
    2
    @Northmaen Im interested in your solution but I dont know how to do the event and set it, could you explain? :)
     
  7. Northmaen

    Northmaen

    Joined:
    Jun 23, 2015
    Posts:
    17
    Hey @MarNevGames , events are fired by the buil-in Player Manager, i did not set them. You can just hook your function like you do with UI buttons for example.
     
  8. T-ruth

    T-ruth

    Joined:
    Jan 27, 2018
    Posts:
    1
    Hey @Northmaen, your solution just saved me, thank you so much!
     
  9. Filip8429

    Filip8429

    Joined:
    Dec 16, 2018
    Posts:
    20
    Thanks for the Code Northmaen! I have a question though. What is camera and virtualCam? is the camera PlayerInput.camera? Then what is virtualCam?
     
  10. kon4u

    kon4u

    Joined:
    May 22, 2021
    Posts:
    1
  11. AlegriaPablo

    AlegriaPablo

    Joined:
    May 15, 2020
    Posts:
    2
    Can you put more screenshots of it please?
     
  12. asdfish82

    asdfish82

    Joined:
    Jan 2, 2022
    Posts:
    1
    I know this is 2 years late but this video works wonders!
     
    Peter77 likes this.