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

Using Unity 2020.3.35 LTS

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

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

<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">
    <Style src="TitleScreenUI.uss" />
    <TitleScreenManager name="TitleScreenManager" class="screen" />
</ui:UXML>

UXML after initial save:

<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">
    <ui:Template name="TitleScreen" src="TitleScreen.uxml" />
    <ui:Template name="HostGameScreen" src="HostGameScreen.uxml" />
    <ui:Template name="JoinGameScreen" src="JoinGameScreen.uxml" />
    <ui:Template name="ManualConnectScreen" src="ManualConnectScreen.uxml" />
    <Style src="TitleScreenUI.uss" />
    <TitleScreenManager name="TitleScreenManager" class="screen">
        <ui:Instance template="TitleScreen" name="TitleScreen" />
        <ui:Instance template="HostGameScreen" name="HostGameScreen" />
        <ui:Instance template="JoinGameScreen" name="JoinGameScreen" />
        <ui:Instance template="ManualConnectScreen" name="ManualConnectScreen" />
    </TitleScreenManager>
</ui:UXML>

UXML after second save:

<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">
    <ui:Template name="TitleScreen" />
    <ui:Template name="HostGameScreen" />
    <ui:Template name="JoinGameScreen" />
    <ui:Template name="ManualConnectScreen" />
    <Style src="TitleScreenUI.uss" />
    <TitleScreenManager name="TitleScreenManager" class="screen">
        <ui:Instance template="TitleScreen" name="TitleScreen" />
        <ui:Instance template="HostGameScreen" name="HostGameScreen" />
        <ui:Instance template="JoinGameScreen" name="JoinGameScreen" />
        <ui:Instance template="ManualConnectScreen" name="ManualConnectScreen" />
    </TitleScreenManager>
</ui:UXML>

UXML after third save (it then clears it out):

<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">
    <Style src="TitleScreenUI.uss" />
    <TitleScreenManager name="TitleScreenManager" class="screen" />
</ui:UXML>

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
1 Like

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.

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.

1 Like