Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. 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

Issues with animator parameter in timeline

Discussion in 'Timeline' started by athert, Nov 13, 2020.

  1. athert

    athert

    Joined:
    Dec 31, 2012
    Posts:
    24
    Hello.
    Im not sure if this issue is more related to timeline or animator, so i hope i have it in correct forum.
    I have direct blend tree in animator with multiple different facial animations where every facial have his own float parameter and i want to adjust this parameter in timeline.
    I created Clip/Track/Mixer script so i can select what animator parameter i want to change, what value it should be etc. and then i just send it to Animator and update it manually (becouse animator will not update in timeline. Maybe there is simple workaround but i was not able to find it).
    Script looks somehow like this (just to give you idea).

    If i start editor, didnt change anything and go right into playmode, it just do what it should do and it changes my facial animations correctly.
    Issues started when im trying to play it in preview mode in edit mode (thats part where im updating animator manually by script). Right now i must say that im 100% sure that i send correct values into animator and when i read value from animator before/after update, it have still correct value of my parameters.
    When i play timeline in preview (after restarting editor), everything is still okay but when i add new facialClip or when im changing values of my parameter (for example blinking), then it starts acting weird and "SetFloat" function starts feeling more like "AddFloat" function. For example, when i set value (from clean editor start) of "blinking" to 0.5, it correctly set value to 0.5, BUT when i change it to 0.35, it then somehow visually looks like 0.85 even when all values says i send 0.35 into animator.
    There is no possible way to revert this issue from animator.
    Later i found that when i update animator manually in timeline, it creates overrides in my animator prefab. When this error occurs and i click on my prefab and revert all overrides, it correctly fix my model and animator.
    So, when i add another part of code before that "for" part for every parameter

    it correctly show my animator parameters in preview mode and everything is nice and smooth.

    My question is, what the hell? Does anyone seen this before and know how to fix this problem? If my animator is not in prefab, it will just go into incorrect state and i cannot fix it so it must stay in prefab (or i will need to restart editor every time i change parameter in my facialClip and thats no-go)

    My assumption is that animator in timeline preview mode is somehow instanced and when i say "set this value and update", he will update and says himself that it will change value +0.5. Then when i do it again for another frame, he will forgot that he already set this value and set +0.5 again, update itself and move bones further and further away, causing model to explode.

    I have this in fixed state for myself but i dont think this is correct way to change parameters in animator and im sure im not only person who tried to change animator parameters in timeline :D Does anyone have idea where i have problem or how i can fix this mistake?
     
    Last edited: Nov 13, 2020
  2. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    440
    I don't think you can use SetFloat in Timeline Preview.

    What you are seeing is the Animator reading the current values from the scene, and using these as default values. This is why your values are accumulating, and it happens because the Animator is not aware that these values are getting previewed.

    The surefire way to do what you want is to use the Animation Track, not SetFloat.
    You may get some success by only putting a single key in the Animation Track for each parameter you want to use SetFloat on, so that the Animator is aware that it needs to revert the values properly, but I think the end result will depend heavily on evaluation order.

    But in general, Animator.SetFloat isn't meant to be used when you're not in-game, and the Animators in the scene aren't meant to be stepped or evaluated outside of Animation Preview, as that will dirty the scene. It will lead to weird results.
     
  3. athert

    athert

    Joined:
    Dec 31, 2012
    Posts:
    24
    Thank you for quick answer!
    Im glad that my assumption was somehow correct :D I will check Animation Track if it will work or not. But do you think this is only preview-editor issue or it can somehow transfer into build game itself? Lets say i will make sure that all prefabs are in correct state when im building game, can somehow SetFloat in Timeline (in my custom code) create some bugs in game where Animator should update itself correctly and not manually like im doing in preview?
     
  4. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    440
    Your track should work at runtime, and I think that besides the fact that it's putting the Animator in a weird state, I don't think it's changing the actual files on disk.

    Still, this will make your authoring experience pretty terrible.
     
unityunity