Search Unity

binding a persistent object to a Timeline in a tempoary scene

Discussion in 'Timeline' started by nathanjams, Sep 4, 2018.

  1. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    So, I just noticed something I should have thought about a while ago.

    I have recently moved our Cinemachine Brain and Main Camera to a persistent scene. However, I use lots of Timeline sequences with the Cinemachine plugin.

    if there is no Brain component attached to the timeline plugin on start, is there a way to have it search for a Brain component in the scene?

    Thanks in advance.

    Nathan
     
  2. TimmyTheTerrible

    TimmyTheTerrible

    Joined:
    Feb 18, 2017
    Posts:
    186
    I am far from an expert but it would go something like this:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Timeline;
    3. using UnityEngine.Playables;
    4. using Cinemachine;
    5. using Cinemachine.Timeline;
    6.  
    7. public class TimsTimelineReplaceBindings : MonoBehaviour
    8. {
    9.     PlayableDirector playableDirector;
    10.  
    11.     private void Start()
    12.     {
    13.         playableDirector = GetComponent<PlayableDirector>();
    14.     }
    15.  
    16.     public void SetBrain()
    17.     {
    18.         CinemachineBrain brain = Camera.main.gameObject.GetComponent<CinemachineBrain>();
    19.  
    20.         var timelineAsset = playableDirector.playableAsset as TimelineAsset;
    21.  
    22.         if (timelineAsset == null)
    23.             return;
    24.  
    25.         for (var i = 0; i < timelineAsset.outputTrackCount; i++)
    26.         {
    27.                 var track = timelineAsset.GetOutputTrack(i);
    28.                
    29.                
    30.                 Debug.Log(track.name + " : " + track.GetType());
    31.  
    32.             CinemachineTrack t = track as CinemachineTrack;
    33.             if(t != null)
    34.                 playableDirector.SetGenericBinding(track, brain);
    35.         }
    36.     }
    37. }
    38.  
     
    nathanjams likes this.
  3. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    304
    Hey,

    Thanks you for this!