Search Unity

Multi Scene

Discussion in 'Cinemachine' started by DavidSmit, Oct 13, 2017.

  1. DavidSmit

    DavidSmit

    Joined:
    Apr 1, 2014
    Posts:
    50
    So far I love Cinemachine and Timeline! Now I'm trying to use them in a Multi-scene setup. Where there is 'main' scene with the main-camera, and sub-scenes containing individual levels.

    The Playable director loses the references to the main camera bindings on play. I've read somewhere that it's not fully supported yet.
    So my question is, what would be the best approach for now?
    And when it most likely will be supported?

    Thanks!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Good question! I think it more properly belongs on the Timeline forum. Try posting it there.
     
  3. DavidSmit

    DavidSmit

    Joined:
    Apr 1, 2014
    Posts:
    50
    Will do! Thanks!
     
  4. Adam_Myhill

    Adam_Myhill

    Joined:
    Dec 22, 2016
    Posts:
    342
    @DavidSmit - Keeping references across scenes is a tricky situation. You can prefab the camera system up and dynamically load it into each scene as needed. We know about the cross-scene linking being an issue, it's a known thing, for now try to avoid any cross scene references
     
    DavidSmit likes this.
  5. DavidSmit

    DavidSmit

    Joined:
    Apr 1, 2014
    Posts:
    50
    Prefabs weren't the way to go for me unfortunately.
    For now I've managed to create a little script that fixes them. It only works for the first track, and if the binding is for the main-camera.

    But for those who are running into similar problems (and are using timeline in a limited fashion), and where prefab isn't an option, this works:


    Code (CSharp):
    1.  
    2. Camera _cam;
    3.     public void FixCinemachineBindings (PlayableDirector dir)
    4.     {
    5.         if ( dir == null )
    6.             return;
    7.  
    8.         if ( _cam == null )
    9.             _cam = Camera.main;
    10.  
    11.         Cinemachine.CinemachineBrain brain = _cam.GetComponent<Cinemachine.CinemachineBrain>();
    12.         TimelineAsset timelineAsset = (TimelineAsset) dir.playableAsset;
    13.         TrackAsset track = (TrackAsset) timelineAsset.GetOutputTrack(0);
    14.         dir.SetGenericBinding(track, brain);
    15.  
    16.     }
    17.  
     
    ruuben, stevenwanhk and Adam_Myhill like this.
  6. tinyant

    tinyant

    Joined:
    Aug 28, 2015
    Posts:
    127
  7. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    This is what I've done:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3. using UnityEngine.Timeline;
    4. using Cinemachine;
    5. using Cinemachine.Timeline;
    6.  
    7. public class CineMachineAdvTrack : Cinemachine.Timeline.CinemachineTrack {
    8.  
    9.     protected override Playable CreatePlayable(PlayableGraph graph, GameObject go, TimelineClip clip)
    10.     {
    11.  
    12.         go.GetComponent<PlayableDirector>().SetGenericBinding(this, Camera.main.GetComponent<CinemachineBrain>());
    13.  
    14.         return base.CreatePlayable(graph, go, clip);
    15.     }
    16.  
    17. }
     
  8. ruuben

    ruuben

    Joined:
    Nov 5, 2015
    Posts:
    11
    Thanks a lot @DavidSmit

    With Unity 2018.2.2f and Cinemachine 2.2.0 your solution save my day!

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Playables;
    4. using UnityEngine.Timeline;
    5. using Cinemachine;
    6.  
    7. public class TimeLinePlaybackManager : MonoBehaviour {
    8.  
    9.       public PlayableDirector playableDirector;
    10.  
    11.       void PlayTimeline()  {
    12.  
    13.                 CinemachineBrain brain = Camera.main.GetComponent<CinemachineBrain>();
    14.                 TimelineAsset timelineAsset = (TimelineAsset)playableDirector.playableAsset;
    15.                 TrackAsset track = timelineAsset.GetOutputTrack(0);
    16.                 playableDirector.SetGenericBinding(track, brain);
    17.  
    18.                 playableDirector.Play();
    19.         }
    20. }
    21.  
     
    DavidSmit likes this.
  9. Drabantor

    Drabantor

    Joined:
    Dec 22, 2017
    Posts:
    4
    The problem that is raised in this thread, i.e. that the Playable director loses the reference to the main camera when there is a scene change, has that been resolved in the lastest version of Unity?
     
    Donvermo and LaurieAnnis like this.
  10. Donvermo

    Donvermo

    Joined:
    Mar 31, 2014
    Posts:
    13
    I am having a similar issue trying to get Cinemachine to play nice with a multi-scene setup. I have an initial scene which loads with it's own dedicated camera which I then want to put in charge of virtual cameras in each scene. This workflow doesn't seem to be support though.
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    If the main camera with the CM brain stays loaded it will auto-detect any vcams that load dynamically, regardless of whether they're in another scene. Timeline bindings, on the other hand, need to manually set as described above.

    Can you give more details about your setup, what you're trying to do, and what exactly isn't working?
     
  12. Donvermo

    Donvermo

    Joined:
    Mar 31, 2014
    Posts:
    13
    Setup
    An initial scene which holds a main camera that is auto loaded through a bootstrap class.
    In another scene I have an additional camera specifically for UI elements which are on a canvas in that scene. (Depth Only, Culling Mask UI, Ortographic)

    The project is 2D and the cameras have a PixelPerfectCamera component.

    Goal
    What I am trying to handle is custom UI interactions where the user can drag around windows etc that remain pixel perfect. I've written a custom handler for the interactions that require a camera reference (hence the in-scene camera)

    Issues
    When using regular cameras this setup renders just fine.
    Using both cinemachine cameras the UI doesn't render at all.
    Using a regular camera for UI doesn't work initially but does work when I disable and re-enable the UI camera.

    Let me know if you need more details.
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    I doubt that the problem is related to Cinemachine. I suspect that there is some other issue that gets tripped inadvertently when you change to CM cameras. I can't really say more than that without seeing the project.

    For sure you shouldn't be using Cinemachine for the UI camera. I don't see what they would bring to the table for that use-case.
     
  14. Donvermo

    Donvermo

    Joined:
    Mar 31, 2014
    Posts:
    13
    Thanks for the interest in the issue and confirming that I am on the right track. I'll report back once I figure out what was causing it.

    EDIT: Finally have it working consistently:

    MainCamera (cinemachine brain) :
    • Main Camera Tag
    • Depth needs to be LOWER than the UI camera
    • Clipping Plane needs to be a negative number to not clip tilemaps
    • Culling Mask should NOT include the layer of the UI Camera
    • PixelPerfectCamera Addon required
    UI Camera (non cinemachine):
    • Depth Only
    • Culling Mask ONLY UI layer
    • Depth needs to be HIGHER than Main Camera
    • PixelPerfectCamera Addon required
    • PixelPerfectCamera Upscale Render Texture required (Without this it just renders void)
    Still unsure as to why Upscale Render Texture setting is required (would love to know why) but it seems to work now.
    Hope this helps others with a similar issue in the future.
     
    Last edited: Apr 7, 2022