Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

removing unused materials and textures

Discussion in 'Editor & General Support' started by Lastrego e Testa, Sep 20, 2012.

  1. Lastrego e Testa

    Lastrego e Testa

    Joined:
    Sep 10, 2012
    Posts:
    14
    Hi there,
    is there any method to get rid of unused materials from an unity project? I'm just wondering if anyone could help me with this problem because I have a huge quantity of materials that are not assigned to specific meshes.
    Furthermore I'd like to know if I have to delete the unused textures manually or the process above replaces them automatically.

    In the meanwhile I thank you!
     
  2. UnityCoder

    UnityCoder

    Joined:
    Dec 8, 2011
    Posts:
    534
    Yes u can remove all unused assets from project. What u have to do Just right click on Scene file in project folder and click on select dependencies, show its show u how much assets u used in a scene.
     
    geethuthrippathy and russisunni like this.
  3. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
    Delete the files in the Project view in Unity. That also deletes them in your computer file structure.

    Do not delete the files in Finder, Windows Explorer or any other way outside Unity as that corrupts the metadata of the project.
     
    russisunni likes this.
  4. Lastrego e Testa

    Lastrego e Testa

    Joined:
    Sep 10, 2012
    Posts:
    14
    Hi UnityCoder, thanks for your reply. Your suggestion is very useful.
    Now I visualize all the assets used. In the same way, I'd like to know if it is possible to visualize all the unused assets. Is there a way to invert the selection?
     
  5. UnityCoder

    UnityCoder

    Joined:
    Dec 8, 2011
    Posts:
    534
    Ha.. Ha.. No i dont know how to do that and i m sure its not possible. But Just do onething with all selected dependencies just right click and export package and save that package, then after create new project and import that package into that brand new project. Thats it.
     
  6. Kragh

    Kragh

    Joined:
    Jan 22, 2008
    Posts:
    657
    You could make a script which took all of your scenes one by one, and made a complete list of all dependencies of these scenes. You could then loop through all assets in the assetDatabase, and see if they were present in this list. If not, delete them.
    There is a but: Scriptet classes or dll's which are just referenced through scripts used in the scene (either by being statically issused from within a class, or from being imported by "Using" directives) won't be noticed by the build-in select dependencies command. Also shader fall backs and cg includes won't be discovered as well. So as long as you only delete materials, geometry, prefabs and such, it would work fine.
     
  7. KristianHJ

    KristianHJ

    Joined:
    May 28, 2010
    Posts:
    350
    Wrote an editorwindow tool that will help. It lists all unused objects by type, and have an easy interface to delete them. Added the tool to the unity asset store: https://www.assetstore.unity3d.com/en/#!/content/22983

    NB: It also lists filesize of files included in build. That should help to reduce buildsize.