Search Unity

Other How to Achieve: Custom AnimationClipPlayable?

Discussion in 'Timeline' started by CaseyHofland, Aug 6, 2023.

  1. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    613
    Hi there, I'm working on implementing cycles in Unity - these would allow for time of day, seasons, calendars, anything that can be considered a "cycle" really.

    Currently I have been naively using
    AnimationClipPlayable
    to, for example, rotate the hands of a clock based on the time of day. Everything about this implementation is great: it scales, it lets you get creative, it's extendable. However, working with
    AnimationClipPlayable
    has become cumbersome, as I am doing a lot of extra work and assumptions in order to get them to do what I want. For example, making a clip only run between 20:00 and 4:00 (think nighttime activity) is a nightmare, with all kinds of calculations, pausing and playing: it's just not sustainable.

    I actually got quite far in the documentation of Playables, but I'm not creating a custom Playable: I'm creating a custom
    AnimationClipPlayable
    , and I don't know the best way forward. Should I:
    1. Create my own
      CycleClipPlayable
      that can hook up to
      AnimationPlayableOutput
      ?
    2. Create my own
      CyclePlayableOutput
      that manipulates an
      AnimationClipPlayable
      ?
    3. Do both, for consistency and control?
    4. Do neither, Playables is a dead API?
    5. Other...
    I found a lot of information on Playables, but I haven't found any best practices or guidelines for how to implement your own stuff. For a start, I am very confused on how I would recreate the
    AnimationClipPlayable
    functionality for
    CycleClipPlayable
    , if that is even possible.

    Linking some of the best minds in Playables right now to ask for help, I would greatly appreciate it <3
    @seant_unity
    @Kybernetik
     
  2. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    613
    Seems like that doesn't really work: the only way to extend the playables API is by using PlayableBehaviour and hook it up using ScriptPlayable<T0> and ScriptPlayableOutput.

    The only problem is: I still don't know how to build a script playable that uses animation clips. I even checked out the SimpleAnimation repo but it's so convoluted and twisted that it does not seem like the solution either: that cannot be the easiest way to hook up an animation.

    Any help with this would be greatly appreciated.
     
  3. CaseyHofland

    CaseyHofland

    Joined:
    Mar 18, 2016
    Posts:
    613
    So the bottom line is: you can't. I solved my own problem by writing a custom PlayableBehaviour that plays and pauses cycles based on time. This works, but since it is so very specific to my use case I opted to keep
    CycleDurationBehaviour
    (as I called it) internal.

    From all the research I did into the Playables API, I would like to say this:

    If you want to extend Playables: don't. Extend Timeline instead. Timeline was made to be extended. Playables is not, and likely never will be.

    Using Playables is perfectly fine though, for what it's worth it's a good API.