Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Does unused materials get into the build?

Discussion in 'General Graphics' started by Porto881, Jan 12, 2016.

  1. Porto881

    Porto881

    Joined:
    Jul 11, 2013
    Posts:
    74
    I´m in the making of texturing parts of my game and I´m wondering about the Materials. Let´s say I have 100 materials in my project but I only end up using let´s say 50 of them. When I then build my game, will only the materials I used "count" and get in to the build?
     
  2. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Yes. Any thing in the resources folder and all scripts get included i think but the rest is only included if used.
     
  3. Porto881

    Porto881

    Joined:
    Jul 11, 2013
    Posts:
    74
    Ok, what counts as the resources folder? I don´t have one :D
     
  4. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    If they are not in a folder called Resources or any folder inside it and they are not used in the scene, they will not be included. This goes for 3D models, materials, textures, shaders, etc.
     
  5. Porto881

    Porto881

    Joined:
    Jul 11, 2013
    Posts:
    74
    Ok! So if I don´t use a Resources folder the build will only include things that is needed for the scene? Just to be sure :)
     
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yes.

    Resources folder is an internal asset bundle, and will eventually get phased out once asset bundles are super easy to use (AFAIK).
     
  7. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,212
    But what counts as usage? If I have a script attached to a GO and one of the public variables is set to a material, does that count? I need to change materials via script, so I'm wondering how to make sure all the needed materials are included.
     
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,021
    Yes.
     
  9. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,212
    I assume that also works with prefabs? (I.e. if a public variable of a script in the scene is set to a prefab, the prefab is included in the build even if it's not in a folder that's normally included?)
     
  10. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    If a material is referenced by anything, a prefab (that is also included by being referenced itself in a scene or prefab), an object in a scene (including renderers) then it will be included.

    For a full list of what gets included in your build, check the Editor log file just after performing a build. It will contain a list of all the assets that were built, and their resultant sizes.
     
    HonoraryBob likes this.
  11. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,212

    If I ensure the inclusion of materials, prefabs, etc, through referencing them in objects in the scene hierarchy, will all that stuff be in memory at all times, or only when the GOs are activated or the assets are otherwise used?
     
  12. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,212
    Any definitive answer on this? I.e. if an inactive GO references assets (materials, meshes) are those assets always in CPU memory or are they only loaded in when the GO is activated or otherwise when its needed?
     
    Last edited: Jul 16, 2017
  13. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Active or not does not matter it's always loaded what is referenced.
     
    HonoraryBob likes this.
  14. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,212
    Thank you. Would that include even assets that are only referenced in a script's public variables? E.g. if a GO has a script with a public variable that is set to prefab X, would prefab X always be loaded in system memory at all times, or just included in the build? I would think it would be the latter.