Why does this sometimes throws NaN to animator resulting in breaking my blend tree completely and not updating value with Animator.SetFloat() after it happens; ?
Its attached to object that looks at a target by slerping. I havent been able to reproduce this constantly, only by randomly moving the target.
Debug.Log doesnt seem to throw any obscure values (should be -1f, 1f or 0 as i only care about y-axis on this case).
If so, then reading backwards, that comes, via line 7, from travel that is set on line 3. That, in turn, is calculated from previousRot. Have you checked for any scenarios where previousRot may be null or otherwise invalid?
I still wasnt able to pin point the actual issue but as workaround i added NaN check where i just set axis.y to 0. Since its only for a frame i didnt notice any jitter in the blend tree i use it for.
if (float.IsNaN(axis.y))
{
axis.y = 0;
}
Also kinda weird Animator allows such value that it breaks the layer (or the float value since layer is pretty much locomotion blend tree.), others override layers still worked fine just not the one with blend tree.
If that suffices, then great and glad you got it working.
However, and I mention this only for completeness, I would make this observation: this is a sticking plaster that merely sidesteps a problem. So on the one hand, this change is possibly fine (dependant upon the actual cause in and of itself- you may find it comes back to bite). On the other, if this was a ‘proper production’ system, you would not want to accept or entertain code of that nature.
I think the issue can happen when previousRot.forward == Vector3.back. its looking in completely the opposite direction from Quaternion.Identity and calling an inverse on a rotation is basically asking for a rotation back to the Identity along the shortest possible path. Since in this case, an infinite number of paths are the shorest path of rotation back to identity an axis of rotation cannot be determined. I’m willing to bet that if you debug.logged out the angle when the error happens it’d likely say 180 (or NAN depending on how it maths it out).
Run a dot product on previousRot and Quaternion.Identity and if the value is super close to -1, you likely need to put in a failsafe for it.
OK after some patient debugging i have solved it i think? What i think was the problem is when start == end the axis will result in infinities (animator doesnt like infinity ). So what i did i added this piece of code. Im not 100% this is the correct math, when it comes to quaternions im kinda just winging it… I no longer was able to produce the issue and i didnt see anything wrong about the behavior.