Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Re-binding missing bindings on a playable director prefab at runtime?

Discussion in 'Timeline' started by DarkStoneDigital, Jun 9, 2021.

  1. DarkStoneDigital

    DarkStoneDigital

    Joined:
    Sep 9, 2018
    Posts:
    12
    I have a system where I Instantiate a prefab with a timeline in it. This timeline uses mostly objects within its own prefab but uses a signal receiver in the scene along with a couple other elements.

    How would I go about identifying the missing binds and re-binding them before playing the director? I found some very old posts from 2017 about rebinding but that method doesn't seem to work anymore and I'm looking to do the reverse where I check for missing bindings and replace them.
     
  2. DarkStoneDigital

    DarkStoneDigital

    Joined:
    Sep 9, 2018
    Posts:
    12
    After some digging with a variant of things posted on the old thread I found; I managed to get a (mildly hacky) work around to re-bind missing objects in a timeline prefab.

    I have a local class in my scene that contains an array of generic Objects and another array of the desired track names that I know will be missing bindings. It also has a unique "bind pack ID" which I use in editor to specify which director assets I am going to need. I will clean this up and make its own class for my own usage but here is what works currently in replacing missing bindings if it aids anyone else as a starting point at least.

    Code (CSharp):
    1.    
    2.  
    3.     public string bindPackID;
    4.  
    5.     public Object[] localAssets;
    6.     public string[] localTrackNames;
    7.  
    8. void Start()
    9. {
    10.         //Get our Objects to replace missing bindings for a specific director
    11.         localAssets = AnimationEventHandler.Ins.GetBidnigns(bindPackID);
    12.  
    13.         //Get the corresponding track names for missing bindings for the same director
    14.         localTrackNames = AnimationEventHandler.Ins.GetBindingTrackNames(bindPackID);
    15.  
    16.         for (int i = 0; i < localAssets.Length; i++)
    17.         {
    18.             //Step through each track and see if their name matches our missing track names
    19.             foreach (var PlayableAssetOutput in director.playableAsset.outputs)
    20.             {
    21.                 if (PlayableAssetOutput.streamName == localTrackNames[i])
    22.                 {
    23.                     //replace missing bind with corresponding object
    24.                     director.SetGenericBinding(PlayableAssetOutput.sourceObject, localAssets[i]);
    25.                 }
    26.             }
    27.         }
    28. }
    I'm including a picture of the editor window even though Unity is being Unity with it's UI drawing issues. But you can see I have two arrays and the track names corresponds with the elements of the same array index. I grab this list using the director ID from a script that sits on the prefab playable director game object.

    bindings.JPG
     
    Last edited: Jun 10, 2021
    DgoodingIndi likes this.