Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

How to know which playables are playing in the playabledirector and which playables just started?

Discussion in 'Timeline' started by Awennor, Jun 24, 2017.

  1. Awennor


    Sep 10, 2015
    Sorry if this has been asked before, but I looked quite hard for the solution on the forums and on the API.

    I wanna know how to know which playables are currently being played inside the director. If I can traverse the entire tree I could find every playable and ask them myself but I don't know how to do that. I also wanna know which ones JUST started playing which I can also do if I can traverse the tree.

    Am I going in the wrong direction here?
    I know I could bind the playable and handle that individual playable but for my use case manual binding would not be interesting.

    BTW, my use case is that I want to know when a certain playable has started without having to bind every single playable of that type separately and without using singletons (trying hard to avoid that)

    Thanks guys!
  2. seant_unity


    Unity Technologies

    Aug 25, 2015

    If the PlayableDirector is playing, then you can access the playables through the playableGraph accessor. The structure of the graph may change based on what type of graph is being played, but I assume it's a timeline?

    If it's a timeline the easiest way is to get the root playable (PlayableGraph.GetRootPlayable(0)), and then start traversing the graph using Playable.GetInputCount() and Playable.GetInput(n). Timeline graphs are tree structures. Playable.GetPlayableType() can be used to get the type of playable, and Playable.GetInputWeight() (>0) and Playable.GetPlayState() (PlayState.Playing) can be used to determine which Playables are presently active.

    As for which ones just started playing, that's a bit trickier. You can check the local time of the playable (Playable.GetTime()) which should be close to 0 for newly active playables, but if the clip supports 'clip in' then this method may not work. An example would be an AnimationClipPlayable that starts the animation clip halfway through - for a 4 second animation and 2 second clip-in, the local time would start at 2.

    Hope that helps!