However my project appears to include all scripts from the project in a web player build. I tested this by creating a new scene and making a web player build from it so it only includes the default camera and nothing else. The build turned out to be 1 MB compressed, with all scripts and dll’s included from the project. Am I missing a “strip unused scripts” checkbox somewhere, is this a bug or a side effect of something else? Here are the stats from the empty scene build:
Ok I went ahead to report this as a bug. The issue can also be reproduced on an empty project with just one dummy script.
What happened
Web player build includes unused scripts.
How can we reproduce it using the example you attached
-Create a new project
-Create a new dummy script (do not include in the scene)
-Create a web player build
-check Editor.log stats - the dummy script is included.
Yes, “assets” as used here in the docs unfortunately only refers to non-script assets. For scripts, we have no way of tracking dependencies like for other assets. Some platforms have dead code stripping so unused code is removed but the webplayer and standalones don’t do that.
One reason for this is that it is a non-trivial problem. If you are using reflection, for example, it is often quite impossible to tell which scripts you are actually using and which you are not.
And in a sense, since the compiled DLLs will actually include all scripts, the scripts are not actually unused.
Ideally, I guess there would be a flag where you can explicitly disable reflection for platforms that support it and thus allow static analysis of which code is actually used.
Sorry to resurrect an old thread, but I’d like to hear what solutions do other developers have for this?
If you amass a fairly large codebase, you have debugging stuff, testing stuff, standard asset scripts, VFX (or other) libraries, you’ll easily get many tens of megabytes of unnecessary code in your web build (or otherwise in a standalone build that’s supposed to be light).
Are there any plugins that aim to manage this? You can use c# compile time directives to prevent certain code from being compiled, but it’s a huge pain to sift through existing (external) code to set something like this up manually.
…I guess what Rene said is right; virtually all you need to do is disable reflection and you should be able to track what code is being used and what isn’t. (Shaders are pretty efficiently stripped with multi compile and whatnot)
[EDIT] I suppose you can try some source control shenanigans, like have a stripped down git branch of your current project, into which you only pull the release-only scripts, from the main branch with the full project.