WebGL error: "Could not produce class with ID 0"
Hi, I am working on a WebGL project with asset bundles. Everything seems to work but I am getting the following error even when I disable 'Strip Engine Code'. Any thoughts? I don't find any reference to a class with ID 0.
blob:http://localhost:8000/d89a9c3f-9b5c-49a3-8e70-0ca3b59f0227:8336 Could not produce class with ID 0. This could be caused by a class being stripped from the build even though it is needed. Try disabling 'Strip Engine Code' in Player Settings.
(Filename: /Users/builduser/buildslave/unity/build/Runtime/Serialize/PersistentManager.cpp Line: 1323)
I'm assu$$anonymous$$g that you mean that this happnens when you enable Strip Engine Code (and not disable).
When this has happened to me I had to guess exactly which code was being stripped, and it could be something basic like $$anonymous$$eshRenderer or something like that.
In short, there's a component (it could be any) you're including in an AssetBundle that is NOT in any asset/gameobject that's being used directly in the editor. By not being in the editor, it is stripped and excluded from the WebGL build.
For example, you may have all your 3D models in assetbundles and none in the editor directly. That would make $$anonymous$$eshRenderer be stripped. When you would load your assetbundles, there would be a reference to $$anonymous$$eshRenderer that is not included in the build.
There are a few possible solutions:
Place an empty gameobject with the missing component in the scene
Place this same gameobject in the Resources folder (haven't tested this one, but should work)
Of course, this does not answer your original question, since I also have no idea how to deter$$anonymous$$e exactly which class is missing (beyond manually checking). Hopefully it helps though.
Thanks @DSL-TailorIt, sorry for the delay.
Unfortunately, this also happens when Strip Engine Code is not enabled.
In theory, the ID should map to the ones in https://docs.unity3d.com/$$anonymous$$anual/ClassIDReference.html
But since there is no class with ID 0, I don't know what to add to the link.xml file.
I am using ParticleSystem and Animator and they seem to be missing in the build so I have added them but still nothing.
<linker>
<assembly fullname="UnityEngine">
<type fullname="UnityEngine.$$anonymous$$eshRenderer" preserve="all"/>
<type fullname="UnityEngine.Sprite" preserve="all"/>
<type fullname="UnityEngine.SpriteRenderer" preserve="all"/>
<type fullname="UnityEngine.ParticleSystem" preserve="all"/>
<type fullname="UnityEngine.Animator" preserve="all"/>
<type fullname="UnityEngine.GameObject" preserve="all"/>
<type fullname="UnityEngine.Texture2D" preserve="all"/>
</assembly>
</linker>
I even tried building with the pre-built engine and still the same issue but with class ID 1049652922.
Well, I have been adding things non-stop to the link.xml file and the missing Particles seem to be back but I am still missing an animated piece of mesh. I guess I'll have to keep adding things until it shows.
Thanks for your time.
Hello again!
I don't see $$anonymous$$eshFilter in the X$$anonymous$$L. Could that be it? It's a commonly used component.
Also, if you're using an animated mesh, could you be missing Skinned$$anonymous$$eshRenderer?
Like I said, it's a guessing game :-) Good luck.
When I recently added an animated character to my project, this error showed up again.
This time the missing class was UnityEngine.Avatar (after a lot of trial/error). Upon closer inspection, it should be noted that the Animator component does have a reference to Avatar, so I guess that makes sense. Still, this might help someone who has the same problem.
Have the same error and can't find what class 0 should be. Have you found out? All other classes are listed here: https://docs.unity3d.com/$$anonymous$$anual/ClassIDReference.html
Answer by paramburu · May 17, 2017 at 03:46 PM
Hi, just to share what I ended up doing, maybe it can help you @Milchbar.
What I noticed was that I was missing some particles, so what I did was start adding as much namespaces related to particles I could think of. That solved the issue but then I started commenting out to see which were really necessary.
<linker>
<assembly fullname="UnityEngine">
<type fullname="UnityEngine.MeshRenderer" preserve="all"/>
<type fullname="UnityEngine.SkinnedMeshRenderer" preserve="all"/>
<type fullname="UnityEngine.MeshFilter" preserve="all"/>
<!--<type fullname="UnityEngine.MeshCollider" preserve="all"/>-->
<!--<type fullname="UnityEngine.BoxCollider" preserve="all"/>-->
<!--<type fullname="UnityEngine.Sprite" preserve="all"/>-->
<!--<type fullname="UnityEngine.SpriteRenderer" preserve="all"/>-->
<!--<type fullname="UnityEngine.ParticleAnimator" preserve="all"/>
<type fullname="UnityEngine.ParticleEmitter" preserve="all"/>-->
<type fullname="UnityEngine.PhysicMaterial" preserve="all"/>
<type fullname="UnityEngine.ParticleSystemRenderer" preserve="all"/>
</assembly>
</linker>
I figured that the particles were the issue because I had two particle emitters and got two "Could not produce class with ID 0" errors on the log.
Hope it helps.
Answer by deniskrop · May 09, 2017 at 04:19 AM
I have the same issue with class 1049652922 - how did you go about including the UnityEngine.Avatar class?
Hello there!
I'm not sure if your question was directed at me, but to simply answer your question you can create a file called link.xml, place it in your "Assets" folder and put the following in it:
<linker>
<assembly fullname="UnityEngine">
<type fullname="UnityEngine.Avatar" preserve="all"/>
</assembly>
</linker>
Unfortunately, I'm not sure that that class ID corresponds to Avatar. It may be some other class. There's a bit of trial and error involved in deter$$anonymous$$ing which class is being "incorrectly" stripped.
Further reading:
https://docs.unity3d.com/$$anonymous$$anual/iphone-playerSizeOptimization.html (ignore the fact that this page is mainly for iPhone; the content about link.xml is consistent with other platforms, as far as I know)
https://forum.unity3d.com/threads/what-is-the-syntax-of-link-xml-file.221867/
Answer by Milchbar · May 17, 2017 at 01:38 PM
Have the same error and can't find what class 0 should be. Have you found out? All other classes are listed here: https://docs.unity3d.com/Manual/ClassIDReference.html