Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Animator blend tree NaN

Discussion in 'Editor & General Support' started by drsalvation, Aug 16, 2023.

  1. drsalvation

    drsalvation

    Joined:
    May 2, 2014
    Posts:
    22
    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?

    upload_2023-8-16_10-6-1.png
     
  2. drsalvation

    drsalvation

    Joined:
    May 2, 2014
    Posts:
    22
    hm, nevermind, just restarting unity entirely worked.
     
  3. isaiahthegrafted

    isaiahthegrafted

    Joined:
    Aug 9, 2023
    Posts:
    1
    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 ;-;
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,558
    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:

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. // @kurtdekker - produce NaNs
    4. //
    5. // To use:
    6. //    - drop on a GameObject
    7. //    - press PLAY
    8. //    - observe either NaN or Infinity (you choose)
    9. //    - drag the running GameObject into your project to make a prefab while Unity runs
    10. //    - press STOP
    11. //    - go look in the prefab using a text editor for things like:
    12. //
    13. //        MyVariable: Infinity
    14. //
    15. //    or
    16. //
    17. //        MyVariable: NaN
    18. //
    19. // And then replace the bad value with 0 (be sure to keep ALL spaces!!)
    20.  
    21. public class DeliciousNaaNBreadOven : MonoBehaviour
    22. {
    23.     public float MyVariable;
    24.  
    25.     void Update ()
    26.     {
    27.         MyVariable = 1 / 0f;    // to make Infinity
    28.         MyVariable = 0 / 0f;    // to make NaN
    29.     }
    30. }



    PROPERLY CONFIGURING AND USING ENTERPRISE SOURCE CONTROL

    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:

    https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

    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:

    https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

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

    https://forum.unity.com/threads/whe...grammer-example-in-text.1048739/#post-6783740

    Share/Sharing source code between projects:

    https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837

    Setting up an appropriate .gitignore file for Unity3D:

    https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

    Generally the ONLY folders you should ever source control are:

    Assets/
    ProjectSettings/
    Packages/

    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):

    https://thoughtbot.com/blog/how-to-git-with-unity

    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
     
    Last edited: Sep 20, 2023