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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question Serialization errors in WebGL build

Discussion in 'UI Toolkit' started by sh_code, Dec 19, 2021.

  1. sh_code

    sh_code

    Joined:
    Apr 8, 2015
    Posts:
    17
    Hello, I'm trying to use the UI Toolkit, just some very basic stuff, 1 UIDocument with 1 Scroll Panel, with several buttons inside it, no custom external style, all the styles for elements are inlined... I haven't even bound any events yet, just displaying the layout.

    Everything works perfectly as it should in editor, but when I run the WebGL version, the UI doesn't display (the rest of the things in game still works properly), and I get the following series of exceptions:

    comics.framework.js:2 A scripted object (probably UnityEngine.UIElements.ThemeStyleSheet?) has a different serialization layout when loading. (Read 56 bytes but expected 128 bytes)
    Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 The referenced script (UnityEngine.UIElements.PanelSettings) on this Behaviour is missing!
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 The referenced script on this Behaviour (Game Object '<null>') is missing!
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 A scripted object (probably UnityEngine.UIElements.PanelSettings?) has a different serialization layout when loading. (Read 48 bytes but expected 200 bytes)
    Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 The referenced script (UnityEngine.UIElements.ThemeStyleSheet) on this Behaviour is missing!
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 The referenced script on this Behaviour (Game Object '<null>') is missing!
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 A scripted object (probably UnityEngine.UIElements.ThemeStyleSheet?) has a different serialization layout when loading. (Read 40 bytes but expected 67808 bytes)
    Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 The referenced script (UnityEngine.UIElements.VisualTreeAsset) on this Behaviour is missing!
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 The referenced script on this Behaviour (Game Object '<null>') is missing!
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 A scripted object (probably UnityEngine.UIElements.VisualTreeAsset?) has a different serialization layout when loading. (Read 40 bytes but expected 3304 bytes)
    Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 The referenced script (UnityEngine.UIElements.UIDocument) on this Behaviour is missing!
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 The referenced script on this Behaviour (Game Object 'UIDocument') is missing!
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 A scripted object (probably UnityEngine.UIElements.UIDocument?) has a different serialization layout when loading. (Read 32 bytes but expected 72 bytes)
    Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
    _JS_Log_Dump @ comics.framework.js:2
    comics.framework.js:2 UnloadTime: 5.699999 ms

    I hope someone will have some suggestions?
    Oh, btw, I have WebGL Compression disabled, since that was causing a freeze on load (at least in the previous version of unity).
     
  2. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    522
    We would definitely need to know the editor version and package version if you are using it to investigate.

    Can you report a bug with this?
     
  3. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    384
    Depending on your version, there used to be an issue with the IL2CPP code stripping that could cause this exact behavior. This only usually happened on a new project that only used a scene with a plain UIDocument, UXML and no custom code.

    The workaround is to create a custom component that refers to UIDocument and to add it in your scene.
     

    Attached Files:

  4. sh_code

    sh_code

    Joined:
    Apr 8, 2015
    Posts:
    17
    Thank you, that actually solved the issue :)
     
  5. sh_code

    sh_code

    Joined:
    Apr 8, 2015
    Posts:
    17
    Sorry, I should have provided that info in the first place.

    Unity 2020.3.25f1

    (possibly relevant) packages:
    "dependencies": {
    "com.unity.toolchain.win-x86_64-linux-x86_64": "0.1.21-preview",
    "com.unity.ugui": "1.0.0",
    "com.unity.ui.builder": "1.0.0-preview.18",
    "com.unity.ui": "1.0.0-preview.18",
    "com.unity.modules.jsonserialize": "1.0.0",
    "com.unity.modules.ui": "1.0.0",
    "com.unity.modules.uielements": "1.0.0",
    "com.unity.modules.unitywebrequest": "1.0.0",
    "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
    "com.unity.modules.unitywebrequestaudio": "1.0.0",
    "com.unity.modules.unitywebrequesttexture": "1.0.0",
    "com.unity.modules.unitywebrequestwww": "1.0.0",
    }

    Should I still submit a bug report even though the code stripper workaround solved it?
     
  6. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    522
    No need to fill the bug, thanks! :)
     
  7. chwar

    chwar

    Joined:
    Mar 29, 2018
    Posts:
    3
    Hi, sorry to necropost, but this is the only clue I have on the very same problem. I tried applying the workaround by attaching the custom script to my UIDocuments, but the serialization errors remain and UIs are still invisible in WebGL builds. Is there something else I could try?
     
  8. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    384
    Which version of the editor are you running?
     
  9. chwar

    chwar

    Joined:
    Mar 29, 2018
    Posts:
    3
    Hi! Thanks for coming back to me. I'm running 2021.2.5f1.
     
  10. yukunlinykl

    yukunlinykl

    Joined:
    Dec 17, 2021
    Posts:
    21
    The same issue to me.
    I use the workaround but the error remain and UIs are still invisible in WebGL builds.

    The Editor's version is 2022.1.0b2.2474
     
    Last edited: Mar 17, 2022
  11. yukunlinykl

    yukunlinykl

    Joined:
    Dec 17, 2021
    Posts:
    21
    I tried 2021.2.15 with the workaround, the errors remained.

    The attachment is the demo project with a SampleScene
     

    Attached Files:

  12. yukunlinykl

    yukunlinykl

    Joined:
    Dec 17, 2021
    Posts:
    21
  13. all_iver

    all_iver

    Joined:
    Nov 11, 2013
    Posts:
    154
    Has anyone been able to verify that this is actually fixed? It is not fixed for me in Unity 2022.2.0a10 (on Linux). Also, the workaround above does not work for me. At runtime I get errors about different serialization layouts and referenced scripts being missing. CodeStripperWorkaround.cs prints "Hello!" and nothing else, so I guess the UIDocument doesn't make it into the build.

    Does anyone know how to get UIToolkit to work in a WebGL build?
     
  14. yukunlinykl

    yukunlinykl

    Joined:
    Dec 17, 2021
    Posts:
    21
    I think the bug has not been fixed in 2022.2.0a10.

    I open my project by 2022.2.0a10 and rebuild to platform WebGL. Nothing changed, just like 2022.1.0.b11.
    No matter whether I use "CodeStripperWorkaround.cs" or not.
     
    all_iver likes this.
  15. yukunlinykl

    yukunlinykl

    Joined:
    Dec 17, 2021
    Posts:
    21
    So does 2022.2.0a12
     
  16. yukunlinykl

    yukunlinykl

    Joined:
    Dec 17, 2021
    Posts:
    21
    I think 2022.1.9f1c1 solve the issue.