Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Handling playables generically

Discussion in 'Animation' started by tree_fiddler_2000, Feb 6, 2019.

  1. tree_fiddler_2000

    tree_fiddler_2000

    Joined:
    Dec 5, 2018
    Posts:
    6
    Hi

    I have some code which deals with Playables, without really needing to care about what concrete type the playables they are (eg. I don't care if its a AnimationClipPlayable or AnimatorControllerPlayable), but I'm having a hard time making my code type agnostic.
    For example, if I want to connect a playable to a mixer, I need to have a value type representing the playable, which means I can't just keep an IPlayable reference around, since the Playable API requires structs:

    // won't compile because Connect() requires a struct
    IPlayable playable = animationClipPlayable;
    graph.Connect(playable , 0, mixerPlayable, 0);


    Is there a recommend way of working with playables so that I can pass them around generically, without caring what concrete type they are?
     
  2. SilentSin

    SilentSin

    Joined:
    Jan 3, 2013
    Posts:
    156
    Have you tried using the "base" Playable struct instead of IPlayable? All playable structs can be cast to and from that struct.

    I ran into similar issues while making Animancer that I was able to solve by keeping a duplicate Playable in my base state class on top of the specific clip/controller/etc playable in their derived classes.