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. Dismiss Notice

Resolved Calling PlayableBehaviour functions with no clips present?

Discussion in 'Timeline' started by pawel_unity979, Sep 4, 2023.

  1. pawel_unity979

    pawel_unity979

    Joined:
    Jul 15, 2021
    Posts:
    3
    Hi everyone!
    I have noticed that a timeline does not call PlayableBehaviour's functions (like ProcessFrame() or OnGraphStop()) when there are no TimelineClips present on track, probably for performance reasons.

    We could use this behavior to perform "return to default" operations on left out data from previously played timelines (that can be skipped). Technically we could use "OnGraphStart()" or "OnGraphStop" functions to clean things up, but it tends to disrupt the editing process (cleaning up animations when stopping on a clip etc.).

    For example:
    MixerBehaviour code:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3.  
    4. public class ExamplePlayerMixerBehaviour : PlayableBehaviour
    5. {
    6.     public override void ProcessFrame(Playable playable, FrameData info, object playerData)
    7.     {
    8.         Debug.Log($"Clips on track: {playable.GetInputCount()}");
    9.     }
    10. }
    Output screenshot:
    example playable log output.jpg

    As you can see, there is no "Clips on track: 0" debug log present from "Example Track 0" track. Is it the expected behaviour? Can we override it somehow? Thank you in advance!
     
    Yuchen_Chang likes this.
  2. Yuchen_Chang

    Yuchen_Chang

    Joined:
    Apr 24, 2020
    Posts:
    105
    By default, if there's no clip and no marker on the track, the MixerPlayabe won't be created. You can override
    TrackAsset.CanCreateTrackMixer()
    to always return true (or to any condition) to preserve the MixerPlayable.
     
    pawel_unity979 likes this.
  3. pawel_unity979

    pawel_unity979

    Joined:
    Jul 15, 2021
    Posts:
    3
    That is exactly what we needed, thanks a lot!