Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Multi Scene

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

  1. DavidSmit

    DavidSmit

    Joined:
    Apr 1, 2014
    Posts:
    47
    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:
    1,637
    Good question! I think it more properly belongs on the Timeline forum. Try posting it there.
     
  3. DavidSmit

    DavidSmit

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

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    312
    @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:
    47
    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:
    101
  7. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    157
    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:
    10
    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.