Search Unity

Feedback What is the point of a TrackBindingType if you can't easily get it from a PlayableBehaviour?

Discussion in 'Timeline' started by tonycoculuzzi, Aug 26, 2021.

  1. tonycoculuzzi

    tonycoculuzzi

    Joined:
    Jun 2, 2011
    Posts:
    301
    This seems so ridiculous to me. Forgive me for being super blunt about this, but it's incredibly frustrating.

    I've been looking through the docs for the past hour and haven't found a way to just easily and quickly get the bound object of a timeline track from a PlayableBehaviour. I'm not talking about using PlayableDirector.GetGenericBinding, that defeats the purpose.

    If this isn't how track bindings are meant to work, then what's the point of them?

    And if this is the point of them, then why is it so complicated to get the bound object?

    Edit: I'm seeing now that it's passed as
    object playerData
    in
    ProcessFrame
    but it's impossible to get it in OnBehaviourPlay or elsewhere.

    This is.. really unfortunate.
     
    Last edited: Aug 29, 2021
    GerritCrayonGames likes this.
  2. adsilcott

    adsilcott

    Joined:
    Aug 30, 2014
    Posts:
    55
    There is a way, but it's convoluted...

    In the TrackAsset:

    Code (CSharp):
    1. public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    2. {
    3.       var binding = go.GetComponent<PlayableDirector>().GetGenericBinding(this) as ExampleController;
    4.          
    5.       foreach (var c in GetClips())
    6.           ((ExampleControlAsset)(c.asset)).Binding = binding;
    7.          
    8.       return ScriptPlayable<ExampleControlBehaviour>.Create(graph, inputCount);
    9. }
    Of course you also have to pass the reference from the PlayableAsset to the PlayableBehaviour

    Code (CSharp):
    1. public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    2. {
    3.     var playable = ScriptPlayable<ExampleControlBehaviour>.Create(graph, template);
    4.  
    5.     var behaviour = playable.GetBehaviour();
    6.     behaviour.Binding = Binding;
    7.          
    8.     return playable;
    9. }
    I couldn't agree with more though. I will never understand why playerData isn't passed to OnBehaviourPlay/OnBehaviourPause. It makes no sense.
     
    Last edited: Mar 2, 2022
  3. Deleted User

    Deleted User

    Guest

    I'm trying this myself and the `Binding` field on the Asset appears to be getting set when I step through the code, but in the inspector the field says "Type mismatch" (although it is the right type) and the field on the Behaviour remains null.
     
  4. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    280
    Run into this problem, I found a solution
    You can get the binding in ExampleMixerBehaviour's ProcessFrame method, then pass that data to your ExampleBehaviour.

    Code (CSharp):
    1.     public override void ProcessFrame(Playable playable, FrameData info, object playerData)
    2.     {
    3.         //all the class like ExampleBinding,ExampleBehaviour etc, you can replace "Example" with your class
    4.         var trackBinding = playerData as ExampleBinding;
    5.  
    6.         if (trackBinding == null)
    7.             return;
    8.  
    9.         int inputCount = playable.GetInputCount ();
    10.  
    11.         for (int i = 0; i < inputCount; i++)
    12.         {
    13.             ScriptPlayable<ExampleBehaviour> inputPlayable = (ScriptPlayable<ExampleBehaviour>)playable.GetInput(i);
    14.             ExampleBehaviour input = inputPlayable.GetBehaviour();
    15.             //now you can feed the playerData's binding to your ExampleBehaviour, to then run OnBehaviourPlay,Pause with binding.
    16.             input.trackBinding = trackBinding;
    17.         }
    18.     }
     
  5. AverageProg

    AverageProg

    Joined:
    Jun 25, 2015
    Posts:
    38
    in the class method overrides (like OnBehaviourPlay) you can find this information in FramData

    info.output.GetUserData();

    The information is out there, it's just that is not presented in a friendly way
     
    DanteRacoon, AdamBebkoSL and Spikebor like this.
  6. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    280
    Thank you! I wish that would be presented in the Default Playable (Unity provide wizard to make Timeline track in that) but I have to go to forum for this.
     
    Last edited: Oct 17, 2022
  7. AdamBebkoSL

    AdamBebkoSL

    Joined:
    Dec 9, 2021
    Posts:
    33
    T
    Wow this is so buried. Thanks.