Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Saving Twice In a Row In UI Builder Causes Errors and Lost Data?

Discussion in 'UI Toolkit' started by adammpolak, Jun 17, 2022.

  1. adammpolak

    adammpolak

    Joined:
    Sep 9, 2018
    Posts:
    450
    Using Unity 2020.3.35 LTS

    Screen Recording 2022-06-17 at 11.28.50.39 AM.gif

    upload_2022-6-17_11-31-26.png

    - I added 4 UXML files into a Custom Visual Element (that is nested in an UXML file) as children
    - I hit "save" and everything is fine
    - I then hit "save" again, and then everything errors and the data is lost

    Am I not saving correctly?

    UXML initially:
    Code (CSharp):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    2.     <Style src="TitleScreenUI.uss" />
    3.     <TitleScreenManager name="TitleScreenManager" class="screen" />
    4. </ui:UXML>
    5.  
    UXML after initial save:
    Code (CSharp):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    2.     <ui:Template name="TitleScreen" src="TitleScreen.uxml" />
    3.     <ui:Template name="HostGameScreen" src="HostGameScreen.uxml" />
    4.     <ui:Template name="JoinGameScreen" src="JoinGameScreen.uxml" />
    5.     <ui:Template name="ManualConnectScreen" src="ManualConnectScreen.uxml" />
    6.     <Style src="TitleScreenUI.uss" />
    7.     <TitleScreenManager name="TitleScreenManager" class="screen">
    8.         <ui:Instance template="TitleScreen" name="TitleScreen" />
    9.         <ui:Instance template="HostGameScreen" name="HostGameScreen" />
    10.         <ui:Instance template="JoinGameScreen" name="JoinGameScreen" />
    11.         <ui:Instance template="ManualConnectScreen" name="ManualConnectScreen" />
    12.     </TitleScreenManager>
    13. </ui:UXML>
    UXML after second save:
    Code (CSharp):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    2.     <ui:Template name="TitleScreen" />
    3.     <ui:Template name="HostGameScreen" />
    4.     <ui:Template name="JoinGameScreen" />
    5.     <ui:Template name="ManualConnectScreen" />
    6.     <Style src="TitleScreenUI.uss" />
    7.     <TitleScreenManager name="TitleScreenManager" class="screen">
    8.         <ui:Instance template="TitleScreen" name="TitleScreen" />
    9.         <ui:Instance template="HostGameScreen" name="HostGameScreen" />
    10.         <ui:Instance template="JoinGameScreen" name="JoinGameScreen" />
    11.         <ui:Instance template="ManualConnectScreen" name="ManualConnectScreen" />
    12.     </TitleScreenManager>
    13. </ui:UXML>
    14.  
    UXML after third save (it then clears it out):
    Code (CSharp):
    1. <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    2.     <Style src="TitleScreenUI.uss" />
    3.     <TitleScreenManager name="TitleScreenManager" class="screen" />
    4. </ui:UXML>
    5.  
     
    Last edited: Jun 17, 2022
  2. RichardWepner

    RichardWepner

    Joined:
    May 29, 2013
    Posts:
    33
    I was able to reproduce this issue using Unity 2020.3.32f1.

    The steps I took were:
    • Create the 5 documents (main document, 4 sub documents)
    • open the main document
    • drag and drop the 4 sub documents into the hierarchy view of the main document
    • save
    • save again
     
    adammpolak likes this.
  3. RichardWepner

    RichardWepner

    Joined:
    May 29, 2013
    Posts:
    33
    Update: the
    UXML
    file is stored properly after the first attempt. If the document is then reopened (e. g. by opening another document), saving doesn't corrupt the file. If the first changes are done and saved, the file is still valid, but the next attempt of saving (whether or not changes were made) will corrupt it.

    I noticed that possibly as a side the "Library" view of the UI Builder resets after the successful save. The selection between "Standard" and "Project" stais, but the scrollposition and the collapse state in "Project" -> "UI Document" are reset.
     
  4. kieranwarrington

    kieranwarrington

    Joined:
    Jul 30, 2019
    Posts:
    1
    Seeing the same issue on my end.
    The same behaviour is occurring when exiting with unsaved changes, and saving following the prompt.
    If you've previously saved with the editor open, saving during exiting will revert any changes made within the editor.
     
    adammpolak likes this.