Unity scripts build settings

Hello guys,

I searched a bit but I didn’t find anything, so here I am:
When Unity builds your game, it compile only scripts associated with scenes in build, or it compile all scripts in the project folder?
E.g: I have created a test scene with some test scripts, but I didn’t include this scene in my build. These test scripts will be included in my build?

Thanks for patience :smile:

If the script is not referenced by any object that is included in your build it will not be included.
The same counts for all assets (excluded the Resources and the streaming assets folder)

2 Likes

This doesn’t sound right. A script can access any class in the .sln project, even if that class (eg MonoBehavior or other) isn’t referenced by GameObjects. Unity have no way of knowing which classes will or will not be referenced by other scripts without doing some serious code analysis which I doubt they do, so I’m pretty sure that all code gets compiled and included regardless of usage.

1 Like

Well, I don’t think they need to do this serious code analysis. I mean, static analysis is pretty straightforward (relatively), and I think it’s enough for this goal.