Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Character pose reset issues when doing runtime binding to timeline

Discussion in 'Timeline' started by Sir_patrickl, Oct 11, 2023.

  1. Sir_patrickl


    Jun 24, 2013

    I'm having an issue where a characters pose gets reset when binding to a timeline at runtime.It then blends into the timeline animation track from the wrong pose instead of what the Animator was playing. The pose seems to be the same one you see when configuring muscle settings for an avatar.

    It doesn't do it for all timelines that are handled the same way but it happens to a few.

    This shows what happens. The second frame is when the timeline binding occurs.

    Timeline Binding Issue.png

    Here are the timeline settings (first track is the relevant one):

    Screenshot 2023-10-11 133650.png

    Screenshot 2023-10-11 133657.png

    And here is the code I use to bind the agents:

    Code (CSharp):
    1. private void PreparePlayableAndStartTimeline()
    2.         {
    3.             var toTarget = m_TargetTransform.position - m_Transform.position;
    4.             toTarget.y = 0;
    5.             var dir = toTarget.normalized;
    6.             var rot = Quaternion.LookRotation(dir);
    7.             m_TargetController.SetRotation(Quaternion.LookRotation(-dir));
    8.             m_Fatality.GetPlayableTimeline(m_Attack, m_AttackerStartPosition, rot, OnPlayableReady);
    9.         }
    11.         private void OnPlayableReady(PlayableDirector director)
    12.         {
    13.             m_PlayableDirector = director;
    15.             BindToPlayableTimeline(director, m_Transform.gameObject, m_TargetTransform.gameObject);
    16.             m_PlayableDirector.stopped += OnPlayableStopped;
    17.             m_PlayableDirector.enabled = true;
    18.             m_PlayableDirector.Play();
    19.         }
    21.         public void BindToPlayableTimeline(PlayableDirector timeline, GameObject attacker, GameObject receiver)
    22.         {
    23.             foreach (var playableAssetOutput in timeline.playableAsset.outputs)
    24.             {
    25.                 switch (playableAssetOutput.streamName)
    26.                 {
    27.                     case "Attacker Track":
    28.                         timeline.SetGenericBinding(playableAssetOutput.sourceObject, attacker);
    29.                         break;
    30.                     case "Receiver Track":
    31.                         timeline.SetGenericBinding(playableAssetOutput.sourceObject, receiver);
    32.                         break;
    33.                 }
    34.             }
    35.         }
    Can anyone tell me what I'm doing wrong here? I've been pulling my hair out over this and can't figure out what the issues is.

  2. devook


    May 21, 2013
    I don't have a solution for this but can +1 this also happens constantly to me. I'm not doing any sort of runtime binding, though. Steps to repro are:
    1. Have a PlayableDirector attached to a GameObject with an Animator targeting a Humanoid rig,
    2. Disable PlayableDirector.PlayOnAwake
    2. Click the GameObject, which puts the PlayableDirector into Preview mode and sets the Animator state to whatever clip is playing on the Timeline
    3. Enter PlayMode: observe the character is stuck in neutral muscle pose until the Timeline is played

    This only happens when the PlayableDirector has been put into Preview mode at least one time since the last time PlayMode was entered, and will happen even if Preview is not enabled and/or the PlayableDirector does not have focus in the Inspector when PlayMode is entered. The "fix" for me is to always start PlayMode twice... The first time I start PlayMode, Animator gets initialized in the bad state, the second time - as long as I don't click on the object with the PlayableDirector attached - it will start without issue.

    Of additional note: When I start PlayMode with my PlayableDirector object selected in the Hierarchy, the Inspector panel reports "This object only exists at Runtime," which is an interesting thing to say when I am in Runtime. Reselecting the GameObject causes the Inspector to redraw appropriately. I suspect whatever hacky shenanigans are happening inside the `#if UNITY_EDITOR` blocks in AnimationTrack are worth a look. Especially lines 927-929 (in v1.7.5) which look particularly sus to me:

    Code (CSharp):
    2. // Create default pose clip from collected properties
    3. if (hasHumanMotion)
    4.     animClips.Add(GetDefaultHumanoidClip());
  3. Sir_patrickl


    Jun 24, 2013
    Thanks for the additional info. I was going to try pre binding the player to the timeline next time I have a chance but it seems like it might still be an issue? In my case I'm not actively modifying the timeline although I do have the timeline window open. If it is somehow related to the editor preview mode I might need to see if the issue persists in an actual build.

    EDIT: After checking that anim referenced in
    it is the t-pose anim that you see when blending in/out of a timeline. So for me at least that doesn't seem the be the issue. If someone knows where the muscle pose animation comes from that might help narrow down the source of the problem.
    Last edited: Oct 12, 2023