Search Unity

IAnimationJob with data from another track

Discussion in 'Timeline' started by pdinklag, Nov 10, 2018.

  1. pdinklag

    pdinklag

    Joined:
    Jan 24, 2017
    Posts:
    154
    I am trying to hook an IAnimationJob into my timeline that receives its data (e.g., the IK mapping weight for a third-party IK solver) from a separate track. I am a bit puzzled on how to achieve this.

    For the weight data, I defined my own track and playable asset types (IKWeightPlayableAsset).

    In order to get my animation job going after the animation clip, I extended AnimationPlayableAsset to hook the job in like so:
    Code (CSharp):
    1. public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
    2. {
    3.     var postProcessor = AnimationScriptPlayable.Create(graph, new IKJob(), 1);
    4.     postProcessor.ConnectInput(0, base.CreatePlayable(graph, go), 0, 1.0f);
    5.  
    6.     return ikProcessor;
    7. }
    What I'm lacking now is some way to get the data from my IK weight playables (which are ScriptPlayables) into the animation job. I could use ProcessFrame to traverse the graph and find my AnimationScriptPlayable and set its job data, but how do I make sure this happens before the animation job's ProcessAnimation is called during the same frame? Also, I want to avoid that the applied IK is "mixed away" by an animation mixer that the AnimationScriptPlayable may be connected to in some more a less direct way.

    What I'd really need is some way to hook my custom IK processor right before the final animation output (behind any mixers), as well as make sure that my weight clips are updated before the IK processor during the same frame.

    How do I go about this? Has anybody faced something similar and if so, can you give me some suggestions? Is there maybe some way to get greater control over how the timeline's graph is constructed?

    Note that I'd like to have all this with the ability to preview - as my ultimate goal is to be able to preview the IK-processed animation in the timeline. So whatever graph modification I do should also work in the editor in the timeline's preview mode.