Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Multi-Display not working on iOS

Discussion in 'General Graphics' started by KamikazePlatypus, Aug 30, 2022.

  1. KamikazePlatypus

    KamikazePlatypus

    Joined:
    Jan 17, 2019
    Posts:
    3
    Hi all. I'm trying to get two different video players to play two different videos, one on my iPhone and one on an external display connected via the Lightning AV adapter. However, no matter what I try, the external display mirrors the phone's display. Here's my code:

    Code (CSharp):
    1. public class MultiScreen : MonoBehaviour
    2. {
    3.     public Camera primaryCam;
    4.     public Camera secondaryCam;
    5.    
    6.     // Start is called before the first frame update
    7.     void Start()
    8.     {
    9.         secondaryCam.depth = primaryCam.depth - 1;
    10.         primaryCam.SetTargetBuffers(Display.main.colorBuffer, Display.main.depthBuffer);
    11.         secondaryCam.enabled = false;
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.         if (Display.displays.Length > 1 && !secondaryCam.enabled)
    18.         {
    19.             Display.displays[1].SetRenderingResolution(Display.displays[1].systemWidth, Display.displays[1].systemHeight);
    20.             secondaryCam.SetTargetBuffers(Display.displays[1].colorBuffer, Display.displays[1].depthBuffer);
    21.         }
    22.         secondaryCam.enabled = Display.displays.Length > 1;
    23.     }
    24. }
    What am I doing wrong? I'm using the built-in renderer (though URP did not work either).
     
  2. marvpaul

    marvpaul

    Joined:
    May 9, 2016
    Posts:
    31
    Perhaps this helps you. I tested on my iOS device with an HMDI adapter and Screen mirroring and this solution works for me.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class SecondScreen : MonoBehaviour
    4. {
    5.     public Camera extCam;
    6.     public Camera cam;
    7.  
    8.     void Start()
    9.     {
    10.         Debug.Log("Connected " + Display.displays.Length);
    11.  
    12.         int displayCount = Display.displays.Length;
    13.  
    14.         // Activate all connected displays
    15.         for (int i = 1; i < displayCount; i++)
    16.         {
    17.             Display.displays[i].Activate();
    18.         }
    19.     }
    20.  
    21.     void Update()
    22.     {
    23.         extCam.enabled = Display.displays.Length > 1;
    24.     }
    25. }
    Use two cameras in your scene. One configured as "Display 1" and the second configured as "Display 2", then assign them to the script.