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.

Bug Weird error on UIBuilder made window

Discussion in 'Editor & General Support' started by RA_Prion_exe, Aug 11, 2022.

  1. RA_Prion_exe


    Aug 2, 2021
    Ok, so this is weird but:

    1. We created a custom window using UIBuilder generating its respective .CS .UXML and .USS files and they worked ok.
    2. Afterward, we relocated the three files to another folder when ordering the project.
    3. We opened the window once again but it didn't show up.
    4. We searched for possible errors but didn't find much. One possible error was that the window or dpi were set to 0.
    5. We verified them by printing them with Debug.Log and they were not 0. We removed the Debugs.
    6. We started trying stupid solutions like setting the window position to... the window position.
    7. This modification made Unity throw a null reference exception. Weird since we printed the values before so we knew they were not null.
    8. We, once again, printed the value with Debug before setting the values and... it worked fine.
    9. We commented the Debug, the position setting and an additional show we used just in case. It still worked fine.
    Final code:
    Code (CSharp):
    2. [CreateMenuItem("New Window/New Window")]
    3. public static void OpenWindow()
    4.         {
    5.             LBSGraphWindow wnd = GetWindow<LBSGraphWindow>();
    6.             wnd.titleContent = new GUIContent("GraphWindow");
    7.             //Debug.Log("wnd:" + wnd.position); // Estos comentarios son vitales para la esgtructura del proyecto porfavor no quitar
    8.             //wnd.position = wnd.position;      // No es broma NO QUITAR!!!
    9.             //wnd.Show();
    10.         }
    The error was present in 2 windows. We replicated step by step in the second window and got the same results. Our best guess is that Unity or one of the files lost the references and somehow at some point debugging the position rect and assigning the value to itself fixed the lost reference. We honestly have no idea.