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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question NaN Local Position Y for all parented by Canvas

Discussion in 'Editor & General Support' started by johntrinh012, Jul 14, 2023.

  1. johntrinh012

    johntrinh012

    Joined:
    Jun 26, 2023
    Posts:
    3
    My "canvas" objects always have a local position of NaN after I close out and open Unity. I try going into Debug Mode, but I still can't change the values.

    upload_2023-7-14_12-2-3.png

    It happened to ALL of the children under "canvas". Could I have done something potentially wrong?
     

    Attached Files:

  2. nekolegends

    nekolegends

    Joined:
    Mar 22, 2023
    Posts:
    2
    I'm having the same issue; when you close Unity 2022.3.4f1, the editor messes with the scene file and makes some parts NaN for canvas items. one way to work around it is to discard changes from GIT before launching. this is a "bug", so please mark it as so instead of question so devs can fix this in next version
     
  3. ElitistJerk

    ElitistJerk

    Joined:
    Oct 1, 2021
    Posts:
    3
    I've encountered this bug as well on Unity 2022.3.4f1. All Y values for children under the UI canvas are set to NaN

    The first time you open the UI prefab, you get spammed with the "graphic rebuild while we are already inside a graphic rebuild loop." error.

    It seems that going into play mode twice fixes the issue, for some reason

    I made the mistake of saving my UI prefab while it was bugged, which meant all the Y values were saved as NaN
     
  4. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,068
    ElitistJerk likes this.
  5. ElitistJerk

    ElitistJerk

    Joined:
    Oct 1, 2021
    Posts:
    3
    Yeah, you're right. It's probably related to that bug. Thanks for posting the link
     
  6. johntrinh012

    johntrinh012

    Joined:
    Jun 26, 2023
    Posts:
    3
    Thanks guys. :)
     
  7. LPSRocha

    LPSRocha

    Joined:
    Jul 13, 2021
    Posts:
    1
    I have been having the same problem and it's very annoying to fix it, but I just discovered that if your canvas is a prefab, you can just revert all "changes", so it goes back to exactly what it was before. Especially useful if the values are not 0.
    Hope this helps
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    The main cause of NaNs and Infinity in hierarchy is animating something to scale = (0,0,0)

    Don't EVER set the scale to zero: it can trigger divide-by-zero errors in the Layout Components of the UI hierarchy.

    The proper way to set scales:

    https://forum.unity.com/threads/onpointerenter-loose-image.1152686/#post-7396073

    NEVER set scale (or any part of scale) to zero or negative.

    NEVER use Vector2 because that makes the third term (Z) zero.

    ALWAYS use Vector3, and make sure that the .z is either 1.0f, or else your non-zero scale.

    Similarly never set scale to Vector3.zero, especially in a UI, because this will cause layout divide-by-zeros and damage all your hierarchy with either
    NaN
    or
    Infinity
    .
     
    Unifikation likes this.