Search Unity

Does Unity include assets in a build that are in scenes that are not in the build?

Discussion in 'General Discussion' started by fuzymarshmello, Jan 22, 2020.

  1. fuzymarshmello

    fuzymarshmello

    Joined:
    Feb 22, 2015
    Posts:
    17
    I am wondering if Unity builds assets that are in scenes excluded from the build. Keep in mind that those assets are used in other scenes, but those scenes are not included in the build. I know that assets in resources folder are built, I am asking about assets not in the resources folder but are present in other scenes that are excluded from the build.

    Thanks
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    For all scenes checked in Build Settings, all assets which those scenes reference are included in the build (and anything those assets references, and those reference, etc). In addition, all code is included and compiled even if not used in any included scene, and everything in any Resources folder is included.

    So if you have assets which are only referenced in scenes you don't have checked in Build Settings, those assets aren't included. But they will still be included if you actually do have them referenced inadvertently.

    So, say you have a scene which includes a prefab of a building, but you have the scene unchecked. But in a scene you do have checked you include a different prefab, which has a reference to another prefab, which has a reference to another prefab, which has a reference to the original building prefab even though you never use that reference in the scene. In that case the building prefab and all its assets would be included in the build even though the first scene which you might think is the only scene which uses it is unchecked.
     
  3. fuzymarshmello

    fuzymarshmello

    Joined:
    Feb 22, 2015
    Posts:
    17
    @Joe-Censored Thank you so much for clearing that up for me! I appreciate it! :)
     
    Joe-Censored likes this.
  4. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    I have models in my builds that I have not referenced as far as I know. is there a way to find whats referencing them and stop them being included? It wastes valuable space. I tried find references in scene but it came back with nothing.
     
  5. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    There's a tool on the Asset Store called "Find References 2" or something like that. I've used it successfully in the past to clean up such things. It just tells you how much stuff is referenced, and by what. Last I used it I still had to manually look at those references to find out what I could delete, but since the project was (fairly) orderly that wasn't too much of a pain.
     
    radiantboy likes this.