Search Unity

Unity scripts build settings

Discussion in 'Editor & General Support' started by Kidara, Dec 20, 2019.

  1. Kidara

    Kidara

    Joined:
    Jul 6, 2017
    Posts:
    16
    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 :D
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    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)
     
    Joe-Censored and Kidara like this.
  3. doarp

    doarp

    Joined:
    Sep 24, 2019
    Posts:
    147
    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.
     
    Kidara likes this.
  4. Kidara

    Kidara

    Joined:
    Jul 6, 2017
    Posts:
    16
    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.