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);
}
}