Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Need to set bindings at runtime

Discussion in 'Timeline' started by BroncoBilli, Mar 22, 2020.

  1. BroncoBilli

    BroncoBilli

    Joined:
    Oct 8, 2017
    Posts:
    71
    I have a PlayableDirector which has an animation track on it (track 0), and I need to set its binding at runtime for the Animator to animate to. When the program starts, the binding is null. In script, I need to set it.

    I'm trying to fool around with getting the Playable Director's PlayableAsset and looking at its enum 'outputs', but that isn't working...
     
  2. mikew_unity

    mikew_unity

    Unity Technologies

    Joined:
    Sep 27, 2016
    Posts:
    109
    Use the SetGenericBinding method on your playable director for this:

    https://docs.unity3d.com/ScriptReference/Playables.PlayableDirector.SetGenericBinding.html

    You need to get a handle to the track that you are binding.

    You can call GetOutputTracks() on the timeline asset and iterate through them to find the one you're looking for:
    https://docs.unity3d.com/Packages/com.unity.timeline@1.2/api/UnityEngine.Timeline.TimelineAsset.html

    Pseudo code something like so (where pd is your playable director and go is the gameobject you want to bind to)

    Code (CSharp):
    1.  
    2. var timelineAsset = pd.playableAsset as TimelineAsset;
    3.  
    4. var trackList = timelineAsset.GetOutputTracks();
    5.  
    6. foreach( var track in trackList)
    7. {
    8.    // check to see if this is the one you are looking for (by name, index etc)
    9.  
    10.  
    11.    if (thisistheTrack)
    12.     {
    13.         // bind the track to our new actor instance
    14.         pd.SetGenericBinding(track, go);
    15.     }
    16.  
    17. }
     
  3. BroncoBilli

    BroncoBilli

    Joined:
    Oct 8, 2017
    Posts:
    71
    Yup. that worked. I think I uncovered a bug? I have an avatar, with an Animator on it, and the animator is looping an Idle animation as long as it's not being played by a Timeline. When I play a timeline, I set a flag in the Animator to shift the animator to a "non animating" state. After the timeline finishes, I set the flag back to false, and the Animator shifts back to playing the Idle animation. The weird thing is that when the Animator goes BACK to playing the Idle animation, the avatar jumps in position from Z Pos = 0, to Z Pos = 7.56! The specific offset doesn't matter.... Anyhow, I looked at the Animator, and I unchecked "Apply Root Motion" and the problem fixed itself. The timeline animation and the animator animation (they're different), both of them are "idle" animations, and don't appreciably move the avatar in the Z position. The fact it jumps to Z Pos = 7.56 makes me think I uncovered some weird goofy bug?
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,194
    The animator continues to play while the timeline runs, it's just that timeline is evaluated last. Would that explain the jump? Could the animator have been in a state that moved it?
     
  5. BroncoBilli

    BroncoBilli

    Joined:
    Oct 8, 2017
    Posts:
    71
    On another thread, a unity person told me the Timeline "overrides" whatever the Animator is doing. That would make a little more sense than "in addition to", from a complexity standpoint, but "in addition to" also makes sense. It's too bad, from the Animator standpoint, that it can't DETECT whether or not a Timeline is "overdriving" (is that a good word?) it. I would love to be able to switch on a state in the Animator, depending on if it's being Timeline-d or not.

    Anyhow, I digress...

    No, the two animations are both "idles". They do NOT move the object around in XZ space, much. In fact, even if we took the XZ delta from the start of either of the two animations (the one on the animator, or the one on the timeline), at no point is the delta XZ on the animation even close to 7 in magnitude, compared to the beginning of the clip. I can see there being some kind of issue if the Timeline idle animation was half-way through it's loop and then for whatever random reason the Animator loop took back over, that there would be an XZ offset issue, but I'm talking a delta of 7+ pops up, and there's no way the animations jump or move the model over 7 meters.

    I'm pretty sure it's a bug. A weird one.
    Are you in Bellevue, SeanT? I work at Microsoft. It'd be easy for me to demonstrate, someday, if there wasn't this covid19 thing going on. :-( We're doing a lot of Unity stuff over here at Microsoft Research. I always have technical issues because we're "hitting it so hard". it's tough to get questions answered quickly...
     
  6. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,194
    Unfortunately I'm not in Bellevue. But feel free to post a small video if possible -

    'In addition to' is a better description, but when dealing with animation between the controller and the timeline it may appear to 'override' as the behaviour can change between Humanoid and Generic models, in particular with non-animated fields in one or the other.

    Admittedly, I'm a bit stumped by a jump of 7 as well, if they are both running idles. My guess was there is an accumulation of root motion happening somewhere. If you apply an ease out to the last clip on the track, and see if it blends out to 7, that might give a hint to the cause. Other than that, do you have multiple animation tracks on the same target? They will layer in playmode, but not in editor.
     
  7. BroncoBilli

    BroncoBilli

    Joined:
    Oct 8, 2017
    Posts:
    71
    While I have you on the hook... I'm having another issue w/ "rotation". The avatar in the scene has a normal forward vector. That is, if you move it "forward" according to its axis, in the Z direction, it's as if it was a normal human, walking forwards. That is, +Z is "face forward". Now, I want this avatar to face the camera, so I put a rotation of 180 into the Y rot... Next, I import an idle animation from Miximo... let's suppose I bake all the parameters into the animation upon import (shouldn't matter). Unity shows +Z on the animation as being "face forward". Super. Now, I put this animation into the animator and preview it. Looks fine, the character idles in place staring at the camera. Now instead, I put the animation onto a Timeline, take it out of the Animator, and preview it. Suddenly, the model is facing AWAY from the camera, doing it's idle thing! I'm pretty sure this is a bug. I described this on another thread, didn't hear back.

    I'm trying to make a video of the above issue with the jump. Will let you know when I've posted it to youtube.
     
unityunity