Search Unity

Question Cinemachine Timeline Track with empty reference

Discussion in 'Cinemachine' started by giantdoor, May 25, 2020.

  1. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    I expected this to be the wanted behaviour, but apparently it's not like that:

    - When creating a new Cinemachine track in a timeline, it won'r have any effect until a CinemachineBrain is assigned to it; that's problematic when a timeline is used in a prefab that is used among different scenes (e.g. a "level end" cutscene), each one with a different brain. I expected it to take the first found CMBrain in the scene when one is not provided (something like a "FindObjectOfType").

    Or am I missing something?

    Peace <3
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    You could write a custom script to bind it to the first brain found when it is instanced.
     
  3. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    I'm trying that but seems that SetGenericBing doesnt work :S
    Here's the code I'm using :
    Code (CSharp):
    1. var timelineAsset = director.playableAsset as TimelineAsset;
    2. var trackList = timelineAsset.GetOutputTracks();
    3. foreach (var track in trackList) {
    4.     if (track.name == "Cinemachine Track") {
    5.         director.SetGenericBinding(track, cmBrain);
    6.     }
    7. }
    Where "cmBrain" is the brain component on my camera GO.
    I tried by feeding the GO and it also doesn't work.
    The track is correctly found tho...
     
  4. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    Oh god, I found out why :S The Clips in the CinemachineTrack are made to hold a reference to the VirtualCamera they blend to; ofc, those references re not saved in the TimelineAsset and I guess the only way is to assign them in the scene? :S
     
  5. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    Ok, somehow I found out I have to get the CinemachineShot from the Track Clips, and then use something like this:
    Code (CSharp):
    1. director.SetReferenceValue(cinemachineShot.VirtualCamera.exposedName, myVirtualCamera);
    But that doesn't seem to work: the camera is already parsed to the timeline, and can even be seen in the Clip inspector, but somehow it doesn't affect the timeline :S
     
  6. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    That's the correct way of binding to the VirtualCamera on the timeline clips, however, it needs to be done prior to the PlayableDirector being Played, or PlayableDirector.RebuildGraph() needs to be called afterwards.
     
    Gregoryl likes this.
  7. giantdoor

    giantdoor

    Joined:
    Sep 11, 2018
    Posts:
    52
    That's great and I got it working as intended, but what about creating an official wrapper class or method for the whole process?
    If Timeline is all about ease-of-use there should be way less need to dig for those answers ^^"
     
    anisimovdev likes this.