Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "Could not produce class with id" mean in Unity?

When I'm building my unity app, I noticed when I use the developer mode, I get an error called "could not produce class with id 362". When I removed a certain object with a script I created, the error goes away. I have no idea what is producing this error or how to fix it.

like image 829
CTHoggard Avatar asked Oct 22 '25 03:10

CTHoggard


1 Answers

Below is a partial answer. First, is some useful research I found while writing it:

Under certain build configurations, either using IL2CPP or using Engine Stripping in WebGL, Unity will aggressively strip out components in order to reduce build size.

One potential error from Unity being overaggressive about it can be could not produce class with id xyz.

The WebGL platform documentation states:

Issues with code stripping

Code stripping might cause issues with your project if it strips code which is actually necessary. This can be the case when you load AssetBundles at run time which contain classes that are not included in the main build, and have therefore been stripped from the project. Error messages appear in your browser’s JavaScript console when this happens (possibly followed by more errors). For example:

Could not produce class with ID XXX

. . .

If you suspect that stripping is causing problems with your build, you can also try disabling the Strip Engine Code option during testing.

From PlayerSettings.stripEngineCodedocumentation

Remove unused Engine code from your build (IL2CPP-only).

If this is enabled, unused modules and classes of the Unity Engine codebase will be removed in IL2CPP builds. This will result in smaller binary size. It is recommended to use this setting, however, you may want to disable it if you suspect this causes issues with your project. Note that byte code stripping of managed assemblies is always enabled for the IL2CPP scripting backend.

In the WebGL platform documentation, there is this suggestion to troubleshooting the issue in general. Even though your problem is seemingly not caused by WebGL or IL2CPP stripping, this might help you:

To troubleshoot these errors, look up the ID (such as XXX in the example above) in the Class ID Reference to see which class it is trying to create an instance of. In such cases, you can force Unity to include the code for that class in the build, either by adding a reference to that class to your scripts or to your Scenes, or by adding a link.xml file to your project.

Below is an example which makes sure that the Collider class (and therefore the Physics module) gets preserved in a project. Add this XML code to a file called link.xml, and put that file into your Assets folder.

<linker>
    <assembly fullname="UnityEngine">
        <type fullname="UnityEngine.Collider" preserve="all"/>
    </assembly>
</linker>
like image 153
Ruzihm Avatar answered Oct 26 '25 10:10

Ruzihm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!