Search Unity

Accessing tracks in script

Discussion in 'Cinemachine' started by Aaron-Meyers, Nov 14, 2018.

  1. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    I'd like to be able to mute/unmute individual tracks on a Timeline. I see that TrackAsset has a "muted" property that has a getter and setter, but I'm not sure how I can access tracks from my timeline. I tried adding some to a MonoBehaviour inspector and it appears to be a Serializable class because the slot showed up, but then I tried dragging stuff from the Timeline panel onto the slot and it didn't work.

    Also tried to find a way to get a reference to the tracks somewhere inside the PlayableDirector, but couldn't figure out a way.

    Anyone know?
     
  2. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    Figured out how to build a list of them in a script:

    Code (CSharp):
    1. List<CinemachineTrack> cTracks = new List<CinemachineTrack>();
    2. foreach ( var track in dir.playableAsset.outputs )
    3. {
    4.     if ( track.sourceObject.GetType() == typeof(CinemachineTrack) )
    5.     {
    6.         cTracks.Add( track.sourceObject as CinemachineTrack );
    7.     }
    8. }
    (I'm specifically looking for CinemachineTracks).

    Still, it'd be cool if the tracks could just be dragged into the inspector slots... they are already draggable in the editor... seems like it would be easy.
     
  3. Aaron-Meyers

    Aaron-Meyers

    Joined:
    Dec 8, 2009
    Posts:
    305
    Hmmm... ok muting/unmuting tracks in script is creating some weird unexpected behaviors. Some virtual cams seem to not work at all in parts of the timeline. Once I mute/unmute tracks in my script do I need to do something like rebuild the playable graph or something? @Gregoryl
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Muting is not supported at runtime. If you need tracks to mute/unmute, you're better off making a separate timeline for those tracks and enabling/disabling it.