TerrainCollider error when stripping is enabled

If stripping is enabled, when downloading a Terrain via assetbundle in a WebGL build we receive this error in the log:

“Could not produce class with ID 154”

…and this is a fatal error. According to class references, ID 154 is TerrainCollider.

This happened in 5.1.x and we just upgraded to 5.2.1p3 hoping it might have fixed the issue. Nope.

Removing “Strip Engine Code” in build settings fixes the error. Is this a known issue?

If not I will submit a bug repro when I get a chance.

It’s not a known issue. To workaround that, you can add to your build a simple scene with an object that uses a TerrainCollider component. That should prevent the TerrainCollider from being stripped out.

However, a bug report would be appreciated.

Thanks, Marco.

:roll_eyes: I probably should’ve made the connection that the terrain code was being stripped out, thus the error. Is it even a bug in this case or just something that needs better explanation for developers-who-need-more-coffee such as myself?

It depends on the situation. The stripping code should detect all the classes used in your assets and your scripts, and make sure that the code for those is not stripped. If it does not do that, then that is a bug (of which we have some). In this case, please report it, and quote the bug number here.

There are cases, however, where the stripping code cannot possibly know what you need. In particular, we cannot know at player build time which classes it might be in AssetBundles you might load at runtime.

Jonas,

We are packaging as much as we can into assetbundles and this includes our terrain data. Thus, it makes sense that the stripping code wouldnt know anything about it.

I did include a TerrainCollider in the scene and the error no longer appeared so I would consider this oversight on my part and not a bug.

Would it be feasible to include a ‘code stripping tracker’ much like the shader tracker that tracks which components are used at run-time so that those components would not be stripped at compile-time?

We have a large, diverse set of assets which can be downloaded at run-time via assetbundles that may use code that could be stripped (thus causing errors such as the one mentioned in this thread). Without knowing exactly which components are stripped by Unity, it’s difficult to know which components to include in the scene (i.e, the TerrainCollider workaround). Currently we just disable code-stripping to be safe.

Yes, this is definitely an area we plan to improve in. Stripping is currently pretty much a black box, where users have very little control nor information of what is going on, which is bad.

For 5.4 I hope to have our new Build Report feature in place which will let you know which modules have been included in the build (and why). I also plan to allow explicit overrides for the stripping of modules, so you can force a module to be included or stripped.

2 Likes