Are all ScriptableObject assets included in the build?

Hi There

I’m thinking of storing some editor data in some ScriptableObject assets but as this data is not required by the game itself, will Unity know that this asset isn’t used. On the flip side, can I load an asset manually that DOES need including and will Unity know to include this asset - would it need to be in the resources folder?


If no scene objects reference a script, Unity is pretty good about cleaning those up when compiling - they won’t be included in your game. If a gameObject or any script in a gameObject references an asset, it will be included in the game. The Resources folders are only for if you want to reference an asset with Resources.Load at runtime. If you’re ever in doubt about whether a needed asset is there, just compile (it takes about 30 seconds) and run the game.

In normal Unity builds (Standalone, Web) all (runtime) classes are included in the build. Unity compiles all scripts into a .NET / Mono DLL. There is a DLL for each compiling group (Standard Assets / editor / normal script) and for each language you’re using. If you’re mixing Unityscript and C# and have some scripts in Standard Assets and also some editor scripts written in C# and UnityScript you will end up with 6 DLL files. only 4 will go into the build since the editor DLLs only work in the editor.


You can find those dlls in the standalone build here : $ProjectName$_Data/Managed/

Unity have to include all scripts since you can use reflection or string based functions to access classes. Just think of Addcomponent("MyClass")

Mobile builds have the special option to strip unused code from the build but when you use reflection to access stripped classes it will crash. As far as i know the string based function calls will work as long as you call it with a string literal. It you build the string at runtime Unity can’t detect that you use the class and would strip the class. That’s why it’s an optional feature in pro and “can” be enabled :wink:

Maybe i’m wrong how the codestripping exactly works but i guess it works like that :wink:

ps. in webbuild the dlls are within the compressed package. As far as i can remember someone managed to “decompress / disassemble” such a package, so your stuff is not “safe” especially the code.

If they are being referenced from the scenes or if they exist in Resources folder, then yes, I think so. Otherwise I am unsure. I wouldn’t expect them to be included since they can’t be used if they aren’t referencable. I guess you could do a quick test project/scene and export the game without a scriptable object, then add a scriptable object and compare the exported games?

You can use this script to see if any objects in your game actually use it and if not clear up your project.

Be warned there is no progress bar on it yet so you just have to be patient and wait for it finish.