Animator blend tree NaN

Hey guys, anyone facing an issue like this?
I created a new animator controller, added 2 float parameters (vertical, horizontal), created a new blend tree, made it 2D freeform Directional, changed the second taken parameter to Vertical.
My blend tree is showing NaN in the vertical parameter. I originally filled in some animations for idle, strafing, walking, etc, but I could never see any of it in action since the vertical floating number is not a number?

I'm using Unity 2022.3.5f1 if that helps. I'm just wondering if this is an editor issue, or if I did something wrong on my end?


hm, nevermind, just restarting unity entirely worked.

that's not helping for me. are you following codemonkey's tutorial by chance? my horizontal parameter is functioning as it should but vertical is throwing "NaN" i've reset Unity entirely twice now and it has not helped ;-;

The trouble with NaN is that it's sorta "poisonous." If you do any arithmetic operator with NaN, the result comes out also NaN... what this means is that if ANYTHING ever divides by zero (the most common way to get a NaN) and you do anything with that NaN, now you're stuck with NaN until you fully overwrite the quantity with a fresh non-NaN quantity.

It's possible the BlendTree stuff is partially backed by some kind of smoothing filter which preserves the NaN.

In the case of a lot of Unity's serialized fields the best way to do this is to use the Reset method in the specific inspector window (upper-right hamburger), but I'm not 100% sure that applies to the Blend Trees.

It might be necessary to remove parts (or all) of your animation controller and rebuild it without the NaN.

Another way if you feel brave is to bring up the .controller file in a text editor and search for NaN and replace it, probably just with the digit zero (0). That's what I'd try first, AFTER backing it up.

This is another really good reason to use source control properly. :)

If you want to practice on a throwaway prefab, here's a little script to make delicious NaN bread for your Indian dining pleasure:

using UnityEngine;

// @kurtdekker - produce NaNs
// To use:
//    - drop on a GameObject
//    - press PLAY
//    - observe either NaN or Infinity (you choose)
//    - drag the running GameObject into your project to make a prefab while Unity runs
//    - press STOP
//    - go look in the prefab using a text editor for things like:
//        MyVariable: Infinity
//    or
//        MyVariable: NaN
// And then replace the bad value with 0 (be sure to keep ALL spaces!!)

public class DeliciousNaaNBreadOven : MonoBehaviour
    public float MyVariable;

    void Update ()
        MyVariable = 1 / 0f;    // to make Infinity
        MyVariable = 0 / 0f;    // to make NaN


I'm sorry you've had this issue. Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work.

Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

As far as configuring Unity to play nice with git, keep this in mind:

I usually make a separate repository for each game, but I have some repositories with a bunch of smaller test games.

Here is how I use git in one of my games, Jetpack Kurt:

Using fine-grained source control as you work to refine your engineering:

Share/Sharing source code between projects:

Setting up an appropriate .gitignore file for Unity3D:

Generally the ONLY folders you should ever source control are:


NEVER source control Library/ or Temp/ or Logs/
NEVER source control anything from Visual Studio (.vs, .csproj, none of that noise)

Setting git up with Unity (includes above .gitignore concepts):

It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place. Digital storage is so unbelievably cheap today that you can buy gigabytes of flash drive storage for about the price of a cup of coffee. It's simply ridiculous not to back up.

If you plan on joining the software industry, you will be required and expected to know how to use source control.

"Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards

1 Like

Just manually change the second parameter to 0. This is an edit box. . . I discovered it suddenly. . .

Just Edit The Value Like This......( Unity is too stupid to give a default value)