Search Unity

Other (SOLVED) Animation Override Controller Clips in script

Discussion in 'Animation' started by Homicide, Oct 19, 2022.

  1. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    657
    Hey guys, i have been beating my head against a wall for too long now with this, so figure i would ask here and see if someone can help lift the burden of dumb off my head.

    So, i have a simple animator attached to a camera, and the controller has a single clip in it, that is an empty clip. The camera most of the time is not animated and has no need, except for on a Track Scene Loaded and Initialized. At this time, i want my camera to use the cinematic clip that the track has.

    So, heres the thing, i have read, and re-read numerous times, the OverrideController scripting api demo codes, and i just don't understand whats going on here.

    Code (CSharp):
    1.  
    2.        private void RegisterReferences()
    3.         {
    4.             vehicleCameraController = GetComponent<VehicleCameraController>();
    5.             animator = GetComponent<Animator>();
    6.  
    7.             overrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
    8.             animator.runtimeAnimatorController = overrideController;
    9.         }
    10.  
    So here i have setup the controller, and then i gget my event to startCinematic, everything working great so far, i see the camera get the clip in the serialized fields i have...

    Code (CSharp):
    1.  
    2.         private void OnStartCinematic()
    3.         {
    4.             Debug.Log($"Cinematic Starting");
    5.             cinematic = TrackController.Instance.track.cinematic;
    6.             overrideController["EmptyCinematic"] = cinematic;
    7.             IsCinematicInProgress = true;
    8.         }
    But now here, when it should assign the clip and play it, nothing happens, ever. Im sure im missing something obvious and easy, but i swear thi sis how the docs demonstrate using this.

    And then i have this method firing when the animation event occurs, and all of it works fine, except the part where the animation is NOT assigned and does NOT play at all. :( /Sad Panda

    One last note of interest (maybe) is that the animation event, only located in the cinmeatic clip, actually does fire. i see it in the debug log, but, the clip is 5 seconds, and theres no way its playing correctly, as none of the camera motion is ever seen. Perhaps it is being assigned and instantly exiting back the empty clip?, i just don't know.

    Code (CSharp):
    1.         private void OnCinematicComplete()
    2.         {
    3.             Debug.Log($"Cinematic Ending");
    4.             overrideController["EmptyCinematic"] = emptyCinematic;
    5.             IsCinematicInProgress = false;
    6.             cinematicComplete.Invoke();
    7.         }
    I'm no animator Jim, just need one single override working and i my animation days are over. lol Ty guys. Imean, the code itself is just elementary crap, but the implementation is clearly not correct. Im stumped.


    EDIT: Well, i realize this post wasnt left for long to fetch a reply, but as i stated, i posted this only after ALOT of time wasted on this. In the end, the solution, toss the entire idea of using an override controller in the dumpster. Found another way to implement the single cinematic required per track loaded as required, and all works great now. Ty anyways. Mod could lock or delete, either way of no concern.
     
    Last edited: Oct 19, 2022