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

Pos Y and Height in Rect Transform are replace by "NaN"

Discussion in 'UGUI & TextMesh Pro' started by VSuper, Sep 20, 2014.

  1. VSuper

    VSuper

    Joined:
    Apr 25, 2014
    Posts:
    5
    Hello,

    I'm making a Scroll Rect GUI, all was perfectly working but this morning when I opened Unity, all the PosY in the rect transform was replaced by "NaN", this bug only affect the GameObject in the mask of the scroll rect... And for the Button, in the text the Pos Y AND the Height are replace by "NaN" and I can't change that!

    How can I change that? Why this happened? I haven't change anything since yesterday but this happened...

    Cordially.

    PS: sorry for my bad english :(
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,183
    Hi, do you have a reference resolution or similar component on the Canvas? We discovered a bug with this (that will be fixed in b19) where we were passing a scale value of 0 to the canvas and that was messing up the data..
     
  3. Usmith

    Usmith

    Joined:
    Apr 7, 2013
    Posts:
    20
    It's still there! 5.3.5p8!
     
    HaiderBassim04 and ThatoMogale like this.
  4. rubenmueller

    rubenmueller

    Joined:
    Oct 15, 2015
    Posts:
    5
    Hackaround:
    If you save the corrupted Scroll Rect as a prefab, you can open the prefab with a text editor and replace all the "NaN" with the values you want (or with 0 and then rearrange everything back in the Unity Editor if you used offsetvalues).
     
    trigoperfec3, yukamui and asaf0125 like this.
  5. bricevdm

    bricevdm

    Joined:
    Nov 4, 2009
    Posts:
    34
    I had the same problem today and the NaN kept coming back (even though I could not find any reference for a 'corrupt' prefab). I'm using TextMeshPro and it seems to be failing with very very long strings without break (in our case something like "TestTestTestTestTestTestTestTestTest [...]". Everything is back in order since I replaced the content with some lorem ipsum instead.
     
  6. alejandro_m

    alejandro_m

    Joined:
    Mar 7, 2017
    Posts:
    1
    Change te inspector to Debug mode (top right corner) there you can change the NaN values back to 0. Go back to normal mode. It worked for me Unity 2017.3.1p4
     
  7. Hassanshin

    Hassanshin

    Joined:
    May 8, 2017
    Posts:
    2
    yea it works! thank you alejandro_m!

    select all gameobjects with Nan position, switch to debug mode, change the anchored position to 0 on x and 0 on y
     
    richardgomes7d likes this.
  8. sgmonda

    sgmonda

    Joined:
    Jul 22, 2018
    Posts:
    1
    @lejandro_m very good tip! thanks
     
  9. StudioZooka

    StudioZooka

    Joined:
    Oct 20, 2018
    Posts:
    4
    i can confirm that this bug is still happening in the 2019.1.6f1
    But this fixed for me... LEGEND!!!
     
    HaiderBassim04 likes this.
  10. Neiist

    Neiist

    Joined:
    Sep 18, 2012
    Posts:
    26
    I was able to solve it on my side by selecting another gameobject with a RectTransform that displays correctly, right-click on the RectTransform, select Copy Component, then select the messed up RectTransform, right-click on it, and select Paste Component Values.
     
    IntelligentCoder and OctoPoulpe like this.
  11. yengNami

    yengNami

    Joined:
    Feb 14, 2021
    Posts:
    12
    This saved me a headache.
     
  12. SK_Design

    SK_Design

    Joined:
    May 19, 2022
    Posts:
    6
    I am still getting the error in the latest 2022 version. Debug mode didn't do anything as value didn't budge from NaN. Had to reinsert prefabs and the error went away.
     
  13. KKITAANIK

    KKITAANIK

    Joined:
    Feb 29, 2020
    Posts:
    2
    I'm still getting this error in version 2022.3.3f1, which is the most recent LTS version as of June 28, 2023. Using Debug mode worked a dream for me. It is sad to see this error is still a thing 9 years later—I was about to just give up on the project so I'm glad I found this thread.
     
    Last edited: Jun 28, 2023
    Plutonosvet and Neiist like this.
  14. damidev0

    damidev0

    Joined:
    Nov 14, 2010
    Posts:
    18
    Same with our project using 2022.3.3f1-3.4f.
     
    Plutonosvet likes this.
  15. Syco753

    Syco753

    Joined:
    Feb 11, 2013
    Posts:
    42
    also the same error: 2022.3.4f1
    It happen only when the recttransform is stretched

    Sure, I can change all values back to 0 (thanks to the poeple above!) but my entire UI is destoyed...
     
    Last edited: Jul 9, 2023
  16. JSaginario

    JSaginario

    Joined:
    Mar 14, 2021
    Posts:
    2
    this is still an issue for me (also 2022.3.4f1)

    does anyone know what causes this??

    EDIT: I don't know if anyone else noticed this, but it seems like it's only the UI Elements I have active at the time of restarting Unity that are effected...
     
    Last edited: Jul 11, 2023
    Plutonosvet likes this.
  17. Neiist

    Neiist

    Joined:
    Sep 18, 2012
    Posts:
    26
    It happens when a value of a RectTransform (UI only) becomes NaN, so to fix it you have to change that value back to a number.

    Although it's very risky for the rest of the data (commit your work before attempting anything like this), you could always make sure that unity serializes things as text, then close unity, and open the scene .unity file where the object is with Notepad++, find the object (or search for NaN) and replace the NaN you find by a number. If it's a prefab you can also open the .asset like a text file.

    Someone pointed out that you should still be able to access the values of a rect transform if you switch the inspector to debug mode (the 3 dots on the upper right corner of the window) that's much safer but I remember it didn't work for me. I had to overwrite the component values entirely and I can't explain why it was the case, it's possible that a combination of scale / rotation / position / anchor resulted in some value within the rect transform to become NaN again, or something like that. Perhaps it can happen when a division by zero happens within the properties of the rect transform.
     
    Last edited: Jul 12, 2023
  18. cembcavus

    cembcavus

    Joined:
    Apr 22, 2015
    Posts:
    1
    my slider's fill's anchored position becomes NaN in mid game. i added this script to the fill objects. i dont know if this is a proper solution but it works for me atm.

    if(gameObject.GetComponent<RectTransform>().anchoredPosition != Vector2.zero)
    {
    gameObject.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
    };
     
  19. Neiist

    Neiist

    Joined:
    Sep 18, 2012
    Posts:
    26
    You don't need `gameObject` if you're already in a `Monobehavior`, if you do that you access twice the unity side of things, once per `gameObject` and once per `GetComponent`, so 4 times in total here, I think what you're doing with `anchoredPosition` isn't necessarily bad but then you don't need to check if it's not zero, just put it to zero without the `if` and save the `RectTransform` in a variable to only do the `GetComponent` once inside `Awake`, instead of once per frame within `Update`.

    Although your NaN probably comes from a parent of your fill object, maybe some of them have non uniform scale or a zero on a scale's z axis for example.

    EDIT
    Didn't mention it but accessing the "unity side" is slow, `this.gameObject` or `this.transform` or `GetComponent` and many other properties and methods have to communicate with the C++ code of unity and doing so has a performance cost that can add up when done many times every single frame.
     
    Last edited: Jul 12, 2023
  20. sudunity12

    sudunity12

    Joined:
    Feb 10, 2018
    Posts:
    12
    I got frustrated due to this NaN value problem, but this save me some time. my entire ui have this problem, Is there way to reset all those ui?
    anyway, thank you at least i can change those non- changing value back now.
     
    scorp2007 likes this.
  21. ppytryrsv

    ppytryrsv

    Joined:
    Mar 11, 2021
    Posts:
    1
    Same issue, version: 2022.3.4f1
     
    scorp2007 likes this.
  22. scorp2007

    scorp2007

    Joined:
    Aug 17, 2014
    Posts:
    53
    Same issue, version: 2022.3.4f1!!!! at the same time, if I change the value in the debug mode, save scene, then I reload the project, they still become NaN. :mad::mad::mad:
     
  23. framacia

    framacia

    Joined:
    Nov 28, 2017
    Posts:
    3
    Having exactly the same issue with the same version. Even after manually editing the NaNs in the .unity file it still happens after loading the scene
     
    CsabCsab likes this.
  24. ZY_bros

    ZY_bros

    Joined:
    Feb 25, 2022
    Posts:
    1
    to change the values you first have to change anchored position
     
  25. CsabCsab

    CsabCsab

    Joined:
    Feb 8, 2020
    Posts:
    2
    I had the same issue and what fixed it for me is making sure when setting the anchored position, that its within the max and min anchor position. Here is a horribly annotated screenshot that hopefully explains it somewhat:
    What can also help is disabling pixel perfect. I hope this helps!
     

    Attached Files:

  26. Whiskey3807

    Whiskey3807

    Joined:
    Apr 4, 2020
    Posts:
    1
    For me it was the CanvasScaler.
    Set it to Expand, close project and reopen, NaN values appear on some children.
    Set it to MatchWidthOrHeight (while values are correct), close project and reopen, values are still correct.

    Just another example of an issue that has been around for over nine years now with no fix in sight. I just feel sad about it. But thankfully with the new pricing model there will finally be enough spare change "to increase code quality" as they say, right? Right?! ;)
     
    aleksandrlis likes this.