Two Animators don't play in Sync
Hey guys,
we have an issue with the unity animator and we need your help.
We want to play a scenario, where two animators play at the same time their animations. For two characters to interact with each other. For this we need a frame perfect playback. And there is the issue.
We figured out that one Animator plays faster than the other, but the Animator and AnimationClip speeds are the same. Also the frame-rate for both clips are at 30fps.
We're using the Unity Animator and call the animations via Trigger-Parameters. The FBX files are exported from Blender.
Has anyone of you faced the same issue before? Do you have any advice?
Please find attached our profiling script, that we wrote to check the delay in detail and a Screenshot of the result.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CompareAnimationFrame : MonoBehaviour
{
public Animator first;
public string currentAnimFirst;
public float currentFrameFirst;
public float animatorSpeedFirst;
public float currentFrameRateFirst;
public Animator second;
public string currentAnimSecond;
public float currentFrameSecond;
public float currentFrameRateSecond;
public float animatorSpeedSecond;
[Header("Diff")]
public float diffSpeed = 0f;
public float diffFrames = 0f;
private float firstDelta = 0f;
private float secondDelta = 0f;
private float firstLastTime = 0f;
private float secondLastTime = 0f;
private void Update()
{
if (first)
{
currentAnimFirst = first.GetCurrentAnimatorClipInfo(0)[0].clip.name;
currentFrameFirst = first.GetCurrentAnimatorStateInfo(0).normalizedTime * first.GetCurrentAnimatorClipInfo(0)[0].clip.frameRate;
firstDelta = Mathf.Abs(first.GetCurrentAnimatorStateInfo(0).normalizedTime - firstLastTime);
animatorSpeedFirst = firstDelta;
currentFrameRateFirst = first.GetCurrentAnimatorClipInfo(0)[0].clip.frameRate;
firstLastTime = first.GetCurrentAnimatorStateInfo(0).normalizedTime;
}
if (second)
{
currentAnimSecond = second.GetCurrentAnimatorClipInfo(0)[0].clip.name;
currentFrameSecond = second.GetCurrentAnimatorStateInfo(0).normalizedTime * second.GetCurrentAnimatorClipInfo(0)[0].clip.frameRate;
secondDelta = Mathf.Abs(second.GetCurrentAnimatorStateInfo(0).normalizedTime - secondLastTime);
animatorSpeedSecond = secondDelta;
currentFrameRateSecond = second.GetCurrentAnimatorClipInfo(0)[0].clip.frameRate;
secondLastTime = second.GetCurrentAnimatorStateInfo(0).normalizedTime;
}
diffFrames = Mathf.Abs(currentFrameFirst - currentFrameSecond);
diffSpeed = Mathf.Abs(firstDelta - secondDelta);
}
}
Hello there, can you confirm a few things for me: 1. Both Animator components have the same Update $$anonymous$$ode. 2. Both AnimationClips have the exact same number of frames (not just same duration). 3. Both Animator components have the same speed. 4. Both Animation States have the same speed.
On a similar note, if you want to have clips play simultaneously you might want to consider Timeline ins$$anonymous$$d of manually controlling Animators, it's designed for doing pretty much exactly this.
Answer by primaerfunktion · Jul 15, 2019 at 09:34 AM
Hey @JamesB, thanks for replying.
Both animators Update Mode is set to the same. We tried Normal and Fixed Time, with the same results.
They actually don't have the same Frame number.
Both Animator Speeds are at 1.
Also the States are set to 1.
So the only thing seems to be the difference in Frame number. But do you think that would result in that sort of difference?
Also, you are right, Timelines seem to be way to go actually. But would be nice it we could make it work with the current setup. Although it doesn't seem achievable at the moment.
Is it possible that the difference in frame counts is causing the error that you are seeing? Do the animations definitely sync up (in Blender)? Is it possible that the triggering of these animations is happening on different frames?
Will need to investigate if it's actually the Frame count causing this, but don't have access to the project till tomorrow. Feel like it would be a bit strange though.
They do sync up in Blender and start at the same time at Frame 0.
What I mean by start at the same time, is the call to animator.SetTrigger() at the same time (not from separate Update calls or something)?
Your answer
Follow this Question
Related Questions
Mecanim muscle system overrides T-pose 0 Answers
How can I stick feet? 0 Answers
my animation isnt importing, and the mesh stays on the T pose 0 Answers
Animations panel: changing one keyframe value makes the other keyframes have the same value 0 Answers
How do I put duplicated, modified animation clip into original model? 0 Answers