Serialization errors in WebGL build

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 ‘’) 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 ‘’) 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 ‘’) 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).

1 Like

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?

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.

7756062–976350–CodeStripperWorkaround.cs (489 Bytes)

Thank you, that actually solved the issue :slight_smile:

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?

No need to fill the bug, thanks! :slight_smile:

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?

Which version of the editor are you running?

Hi! Thanks for coming back to me. I’m running 2021.2.5f1.

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

I tried 2021.2.15 with the workaround, the errors remained.

The attachment is the demo project with a SampleScene

7970199–1022358–Test9.2021.2.15f1c1.zip (304 KB)

According to

This bug was been fixed in 2022.2.0a4
The latest version I can download is 2022.1.0.b11.

Let’s wait.

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?

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.

1 Like

So does 2022.2.0a12

I think 2022.1.9f1c1 solve the issue.