Search Unity

Get The PlayableOutput a Root Playable is Connected To?

Discussion in 'Timeline' started by ModLunar, Mar 8, 2018.

  1. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    I feel like this is a silly question but is there a way to do it? If I have a playable in my graph that I know, can I see the PlayableOutput that it's connected to, if is?


    For example, if I create a TimelinePlayable with the static method TimelinePlayable.Create(...), it'll return me the Playable that was inserted into the graph. But it can auto generate the PlayableOutput(s) needed for it to work.

    Is there a better way than looking through all the outputs with this?
    Code (CSharp):
    1.  
    2. Playable timelinePlayable = TimelinePlayable.Create(...);
    3. for (int i = 0; i < playableGraph.GetOutputCount(); i++) {
    4.     PlayableOutput output = playableGraph.GetOutput(i);
    5.     if (output.GetSourcePlayable() == timelinePlayable) {
    6.         //Yay I found an output that the timeline playable is connected to!
    7.     }
    8. }
    9.  
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    All the outputs are connected to the timeline playable. There is a Get/SetSourcePlayableInput that corresponds to the input port that the subgraph for that track lives on.

    Right now, the order of the tracks from timeline.GetOutputTracks() matches the order of the playable outputs, with one exception - in editor only, humanoid tracks prepend an additional output to do the T-Pose of the character.

    PlayableOutput.GetReferenceObject() also stores a link to the track, if you want the easiest identification.
     
    ModLunar likes this.
  3. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    Oh I see. Cool, so if there was a graph with 2 separate timeline playables, no crazy blending stuff between them, and each had 3 tracks, then...
    - There'd be 6 PlayableOutputs
    - The first 3 PlayableOutputs connected to the first timeline would return 0, 1 and 2 for their GetSourceInputPort()s
    - The second 3 PlayableOutputs connected to the second timeline would return 3, 4, and 5 for their GetSourceInputPort()s
    Is that right?

    Oh wow that's convenient, I should look into the GetReferenceObject() cause it sounds I could use that too with my own custom playables, right?
     
  4. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    This was a while ago, but in general, if you're in the ProcessFrame function of a PlayableBehaviour, I literally just realized that you can use the FrameInfo info's "output" property:

    https://docs.unity3d.com/ScriptReference/Playables.FrameData-output.html

    This only works if you're in the middle of evaluating the graph, but it is SUPER useful! I was going crazy not knowing how to get the PlayableOutput in question haha.