Search Unity

Normalized Progress in ProcessFrame

Discussion in 'Timeline' started by Deleted User, Sep 11, 2018.

  1. Deleted User

    Deleted User

    Guest

    I've been searching for the cleanest way to get the normalized progress of a playable behavior in it's ProcessFrame method. The most common one:

    Code (CSharp):
    1. var progress = playable.GetTime() / playable.GetDuration();
    works well most of the time, but it completely breaks with extrapolation (and clip-in/blending I'm assuming). GetTime sensibly returns 0 during pre-extrapolation and the clip duration after post-extrapolation. From digging around in the clip API, this is similar to the clip's ToLocalTime method. But GetDuration always returns the extrapolated duration and I can't find a reliable way to get the un-extrapolated duration solely from the playable.

    I've also seen suggestions to pass the clip reference first to the clip assets in CreateTrackMixer, and then again into the behaviors in the clip's CreatePlayable method (see https://forum.unity.com/threads/trying-to-get-percentage-of-the-way-through-playable.503672). This...works. But it adds a ton of code overhead to an already awkward API and I'm not sure if it supports time scaling because it's using the clip asset and not the graph. Is this really the best solution at the moment?
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    It is, for now. Timeline does a lot more manipulation of time than is supported in the Playable API, so you will need a reference to the timeline clip to account for non-extrapolation duration, clip-in, etc...
     
  3. Deleted User

    Deleted User

    Guest

    Thanks for the clarification. I hope the timeline team considers exposing some sort of normalized progress API on the playable or in the default mixer, it would make simple custom clips a bit easier to work with.