Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

What's the best way to manage massive PlayableDirectors?

Discussion in 'Timeline' started by zIyaGtVm, Jan 23, 2019.

  1. zIyaGtVm


    Dec 27, 2017
    First of all, I have several characters [let's call them C1 C2 C3...]
    and different kinds of interactive scene-areas{such as rooms' doors, stairs, elevators}

    It's a N-to-M mapping as each character may has special animation for enter a same door, or one character C1 may has different behavior to scene-areas.

    Try 1. Every character has a PlayableDirector with all the sourcebindings & references params for all situations.
    In other words, once I make a new timeline area, I need to redo the whole bindings for every character.Reference & Binding may be missing if cross-scenes.

    Try 2. Every scene-area has its own PlayableDirector and packages all the reference params(child gameobjects) it needs in a prefab, so that references won't lose.
    As you can see it's a prefab : yellow point is door's position ; red point is where character's transform should begin to walk to door; blue point is where character should stop at.
    Every character also has a PlayableDirector but this time this PlayableDirector only cares about his behavior animation ( walking, opendoor, sit down ,etc ...)

    I make a timelineAsset for the door, with 2 tracks, Transform track is for keying movement no matter who come to open this door,
    The other track is a ControlTrack which is used for calling relatived timelineAsset on character's PlayableDirector.
    TL;DR. scene-area PD controls movement, Character PD controls self-animation called by ControlTrack.

    The problem I just find:
    Open Room Door has 3 timeline steps;
    Character2 is chasing Character1, C1 enters a room, C2 also enters the room while scene-area playabledirector is already playing for C1.
    Then room's PD begin to play step2 for C2, C1 is shutdown.
    Are there any way to make the playabledirector work for two or more objects in the meantime?

    Sorry for my bad English,I'm not sure if you could understand my purpose.
    Runtime rebinding maybe an approach however, in my opion I feel it's not quite efficient for iterator all trackname & tracktype all the time.

    The goal is avoid exhaustion binding work for N-to-M mapping, I know you must have smarter solutions.
    Any advice will be appreciated!
    Last edited: Jan 23, 2019
  2. seant_unity


    Unity Technologies

    Aug 25, 2015
    This might be your best option, but I'm not sure what you mean by 'all the time'. Rebind once before you play the director. You could write a Monobehaviour that stores the tracks that need to be rebinded to avoid searching by name (the tracks themselves are assets). As for control tracks, there is a scripting feature you can use:

    You can set the name via script (when you build the timeline): controlPlayableAsset.sourceGameObject.exposedName = "MyCustomTag", then use that on the playable director.

    playableDirector.SetReferenceObject("MyCustomTag", gameObjectToBind). That should be more efficient than searching for timeline to set the control track reference.
  3. zIyaGtVm


    Dec 27, 2017
    Thanks for your prompt reply Seant!
    I stored the tracks and their clips in a Monobehaviour under editor mode, then when character entered trigger, I pass the timelineAsset to character's PlayableDirector and tried to restore bindingvalues.
    The ControlTrack worked fine however my TransformTrack didn't work.
    May I ask if something else should be done to SetReferenceValue for a custom/normal type track, such as TransformTweenClip made by Default Playables.

    Another question:Should these exposedName stringkey never be the same ? Or could there be two "MyCustomTag" stand for two controltrack source in two different Monobehaviours?Thanks.

    Code (CSharp):
    2. public void StoreAOT()
    3. {
    4.     var tracks = sampleAsset.GetOutputTracks();
    5.     foreach (var track in tracks)
    6.     {
    7.         if ( == "Transform Tween Track")
    8.         {
    9.             transTrack = (TransformTweenTrack)track;
    10.             foreach (var clip in track.GetClips())
    11.             {
    12.                 transClip = clip.asset as TransformTweenClip;
    13.                 transClip.startLocation.exposedName = "sp";
    14.                 transClip.endLocation.exposedName = "ep";
    15.             }
    16.         }
    18.         if ( == "Control Track")
    19.         {
    20.             controlTrack = (ControlTrack)track;
    21.             foreach (var clip in track.GetClips())
    22.             {
    23.                 controlClip = clip.asset as ControlPlayableAsset;
    24.                 controlClip.sourceGameObject.exposedName = "MyCustomTag";
    25.             }
    26.         }
    27.     }
    28. }
    30. private IEnumerator PlaySequence()
    31. {
    32.     playerPd.playableAsset = sampleAsset;
    34.     playerPd.SetGenericBinding(transTrack, callerGo);
    35.     playerPd.SetReferenceValue("sp", startPoint);
    36.     playerPd.SetReferenceValue("ep", endPoint);
    38.     playerPd.SetReferenceValue("MyCustomTag", callerGo);
    40.     yield return new WaitForSeconds(2f);
    41.     playerPd.Play();
    42. }
    Last edited: Jan 24, 2019
  4. seant_unity


    Unity Technologies

    Aug 25, 2015
    The exposedName key can be shared among different clips if you want them to all refer to the same object. Otherwise they should be unique.

    For the transTrack, I think you need to set callerGo.transform in the SetGenericBinding call, and startPoint.transform/endPoint.transform in the SetReferenceValue calls.

    Control tracks bind to GameObject, but the transform tween track uses Transforms.
    zIyaGtVm likes this.
  5. zIyaGtVm


    Dec 27, 2017
    Thanks~ You're definitely right. The problem is source object type.
    Is there any api for clean an existing exposedName?
    Last edited: Jan 24, 2019
  6. seant_unity


    Unity Technologies

    Aug 25, 2015
    I'm not sure I follow what you mean. The number is just the hashcode of the string.