Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Timeline cutscene preview works fine with humanoid in preview mode but not play mode?

Discussion in 'Timeline' started by jeffman1, Jun 16, 2020.

  1. jeffman1

    jeffman1

    Joined:
    Oct 21, 2013
    Posts:
    26
    I have a object that is working in preview mode on timeline but not in play mode on the timeline. I have a player character the is using the 3rd person character prefab standard asset (I threw in my own model instead of Ethan's which most tutorials suggest). In play mode, oddly the mouth animations play from timeline but not the actual body movements. How can I force the animation controller to stop the default idle motion and player from moving around and start to play the cutscene animations instead? Am I missing something small that I am overlooking? A setting maybe?
    What I am trying to do:
    1. Stop character at cutscene position and disable player movement. Playing the idle animation from the animation controller initially works to stop the character but removing it causes the character to just keep going on. It does not stop the player from moving around though.
    2. Play the cutscene animation on the player character through timeline. I can only get the facial animations to play oddly but the rest of the body on the character plays the idle animation. This works in preview mode though which I do not understand.
    3. I want to have him play an animation from the animator called "battlereadyidle" (a different idle) to show he's ready to fight once the cutscene finishes.

    Things I have tried:
    1. I have a simple script that tried to remove the animation controller in one test of my code, played the idle animation which only stopped the character but doesn't prevent the player from moving the character, and even stopped playback from the animation controller.
    2. Setting various settings in timeline such as Animation Extrapolation and just playing around has not worked so far but I may have missed something.
    3. Looked for a Root Motion option which is handled by script with the third person character controller so this does not work in this instance.

    Using unity 2019.3.15f1. Yes, my animations are from external files and not created with record in timeline if this is asked. Yes, the cutscene camera object is disabled until I collide with a invisible box object executing my script to stop the character and play the timeline animation.

    My code with what I've tried disabled. The enabled parts are what I can get to partially work in play mode.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Playables;
    5.  
    6. public class DavidGoliathCutsceneEnter : MonoBehaviour
    7. {
    8.     public GameObject HumanPlayer;
    9.     public GameObject cutsceneCam;
    10.     public PlayableDirector CutsceneDirector;
    11.     public RuntimeAnimatorController controller;
    12.     void OnTriggerEnter(Collider other)
    13.     {
    14.         UnityEngine.Animator test;
    15.         GameObject DavidCutSceneEnd;
    16.         GameObject HumanPlayerModel;
    17.         HumanPlayerModel = GameObject.FindGameObjectWithTag("MainCharacter");
    18.         DavidCutSceneEnd = GameObject.FindGameObjectWithTag("RespawnCutScene");
    19.  
    20.         test = HumanPlayer.GetComponent<Animator>();
    21.         test.StopPlayback();
    22.         //  test.Play("DavidIdle");
    23.  
    24.         //CutsceneDirector = GetComponent<PlayableDirector>();
    25.         //CutsceneDirector.Play();
    26.         cutsceneCam.SetActive(true);
    27.  
    28.  
    29.     }
    30.     void OnTriggerExit(Collider other)
    31.     {
    32.         // CutsceneDirector = GetComponent<PlayableDirector>();
    33.         // CutsceneDirector.Stop();
    34.         UnityEngine.Animator test;
    35.         //test = HumanPlayer.GetComponent<Animator>();
    36.         //test.runtimeAnimatorController = controller;
    37.         //test.StartPlayback();
    38.     }
    39.  
    40. }
    My Character's properties page:


    Timeline Setup:
     
    Last edited: Jun 16, 2020
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,309
    Have you tried disabling the 3rd person controller scripts before playing the timeline? The controller scripts appear to use FixedUpdate() to move the character and OnAnimatorMove() to override the root motion. If it works in preview but not in playmode, it would indicate that scripts that only run in playmode are the culprit.

    OnAnimatorMove() could be problematic for timeline, but as for why only the facial animation is playing, it may be that something is playing _after_ timeline (but not updating the face). I haven't dug too deeply, but normally the animator controller plays and then timeline, but maybe it has something to do with the animator updating with physics (which timeline doesn't support).

    As an alternative, you can hide the character and un-hide a clone to play without any scripts to play on the timeline.

    Apologies for not giving a more definite answer. The fact that an animation is partially playing makes me think I'm missing something here.
     
  3. jeffman1

    jeffman1

    Joined:
    Oct 21, 2013
    Posts:
    26
    I will try disabling the scripts because I think that disabling them would cause the character to play properly. I found a code sample while googling and will try it out. I believe you are right and I just was not thinking about it at the time. It seems that the controller script was causing movement and that's for the weird movements but we shall see.
     
  4. jeffman1

    jeffman1

    Joined:
    Oct 21, 2013
    Posts:
    26
    I tried the clone but it causes more problems and does not show up in preview or play mode sometimes at all (buggy behavior?). so, disabling the scripts cause him to stay in a running animation and continue still. I tried removing the OnAnimatorMove property and it does give back the root motion disable/re-enable option. However, my character disappears in PlayMode versus preview. I need animator because its easier because of humanoid setup.
     
  5. jeffman1

    jeffman1

    Joined:
    Oct 21, 2013
    Posts:
    26
    Oh, I have something that's weird too happening. Trying reimporting a 3d model and add an animation controller. I had this happen to me after switching out between timeline and adding an animation controller 2-3 times:
    upload_2020-6-17_15-14-23.png
     
  6. jeffman1

    jeffman1

    Joined:
    Oct 21, 2013
    Posts:
    26
    You know what? I think its playing the animation after looking at it in playtime but cutting off the ending part only of an animation. I think if you have solutions for it the hold the ending position in timeline during play mode that might help me determine this.
     
  7. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,309
    You can set the playable director wrap mode to Hold, and it should hold the last frame of the timeline.
     
    jeffman1 likes this.
  8. jeffman1

    jeffman1

    Joined:
    Oct 21, 2013
    Posts:
    26
    Nope, setting it still plays the idle animation on the character with the face moving and talking it appears in playmode but in editor mode its playing just fine. I thought it might change something. Weird for it to play fine in timeline in editor mode but not play mode.
     
  9. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,309
    Hmm..hard to say why without more context, but it still sounds like something is playing on top of the timeline. When timeline plays, it does not interrupt anything (like the animator controller), it's usually just the last one evaluated, but it sounds like something else is playing afterwards that does not animate the face.
     
    jeffman1 likes this.
  10. jeffman1

    jeffman1

    Joined:
    Oct 21, 2013
    Posts:
    26
    I think I figured it out by a miracle (you can say chance): turns out the avatar prevented the animation from working. Maybe I can remove it at runtime and put it back in when the clip ends. Hope this helps someone else. I just am having a weird problem but I believe I am not running my camera script correctly. I think I have not activated something because the camera doesn't show my character after the cutscene now. For anyone, wondering this is with Unity 2019.3 and you can have the animation controller and third person scripts running from standard assets but update the third person controller to the latest version first.
     
    Last edited: Jun 21, 2020
  11. jeffman1

    jeffman1

    Joined:
    Oct 21, 2013
    Posts:
    26
    For reference, use a timeline api playable track, clip, and asset as shown for lights below except change to track type to avatar and you can have this as a timeline work around to continue working with animator in unity while still using timeline as well if the avatar causes anyone else problems(only works with the unity controllers and I've only tested it with the third person controller):
    https://blogs.unity3d.com/2018/09/05/extending-timeline-a-practical-guide/
    P.S. remember to use process frames just to capture the avatar. to add it back to the character after the timeline or cutscene is over with use the onbehaviorpause from here:
    https://forum.unity.com/threads/cod...ic-at-the-beginning-and-end-of-a-clip.661315/
     
unityunity