- Home /
Animator - Animation State normalizedTime is not normalized
Normalized value is meant to be between 0 and 1.
void Update()
{
AnimatorStateInfo asi = GetComponent<Animator>().GetCurrentAnimatorStateInfo(0);
float norm = asi.normalizedTime;
Debug.Log(norm);
}
Amazingly (or most likely sadly...) this will display anything from infinite negative to the opposite.
I have difficulty this is meant to be this way. Or someone needs a refresh on normalized value.
I am still using 5.3.3 so is this part of the whole "We screwed it all" version or is it still in the latest one as well and honest...that can't be...
I understand I can't add some code to check and stop the animation but this is just pure solid gold rubbish.
That code throw you no errors? :) Perhaps a CS0119? :P
Anyway, did you set the start and end frames of the clip to be different to the default in the Anim Import?
Nope no error, the missing parenthesis is a typo. I created the animation myself, it is a basic movement of a UI.
Ah so its made with the Animation window? Do you have an external animation, say from 3DS$$anonymous$$ax or Blender to try?
Answer by NosVidz · Apr 05, 2016 at 12:11 PM
Where did you get that from? Normalized vectors have a magnitude between 0 and 1, yes. But normalizing doesn't mean putting everything between 0 and 1. http://docs.unity3d.com/ScriptReference/AnimatorStateInfo-normalizedTime.html The integer part is the number of time a state has been looped. The fractional part is the % (0-1) of progress in the current loop. So if your normalized time is > 1, you finished your animation at least once.Normalized value is meant to be between 0 and 1.
Ok so it is not normalized as normalization which consists in setting a value within a range, most likely between 0 and 1. True you can normalize to anything but by default you assume 0 to 1.
In that case the fractional part is the normalized value. Funny, the value keeps growing even though my animation is stuck at the end.
I would have thought that because of the na$$anonymous$$g it would be obvious.
In an imported animation you get to specify if the animation loops or not. Where can you do this in an Animation Window-created animation?
When you select the Animation in project panel, it shows some basic information. There is loop toggle.
This doesnt account for the -infinity though. Or do you think this is either a product of a Frame 0 animation or a very small decimal?
I almost was going to call you out on being against the documentation, when I realized that I was getting AnimatorStateInfo mixed up with AnimationState which treats normalized time as a different thing. Unfortunately when I googled AnimatorStateInfo that was one of the top results so I ended up in the wrong place. To future Googlers, beware. There IS a difference!
The fact that Unity also packs a separate piece of information to the same value doesn't mean it changes what normalization means. If you disregard the loop iteration part (or if you have an animation that's not looped) you still get 0-1 as you expected. If you look into normalized position in ScrollRects, you also get 0-1. It could be a different range(like 0-100) but it's more convenient to keep it in 0-1 as you get the same level of intuition but you don't need division(curr value / max value) before using the value itself. It's understandable to expect just that. Anything else is just an exception(and I guess this packing is also a matter of convenience).
Answer by FrostFT · Apr 06, 2018 at 02:53 PM
I think it mean normalizedTime return value > 1 beacause animation is looped. You can get fractional part of float like this:
float norm = asi.normalizedTime % 1;
It will be between 0..1