- Home /
Find Unused Assets In Project
I read in another QA that unused assets are not included in the final build, so they don't put down the game performances.
If Unity is able to exclude those assets on build phase, is it also able to tell me which assets are unused then, so I can clean them up from my disk? How do I do it?
I've seen the "Select Dependancies" action under the "Assets" menu, but it only shows my items relative to the one I selected.
Note
Regarding this very old question, fortunately it is now easy to do:
https://stackoverflow.com/a/49481451/294884
It's that easy nowadays.
Answer by Bunny83 · Apr 12, 2011 at 11:47 AM
Unity don't include unused assets in your build. Only assets that are referenced by a scene (that is included in the build) and all assets from the resources folder are included in the build. As far as i know there's no way to "clean up" your project automatically. "Clean up" would mean to completely delete assets and such a task should not be automated ;)
If you want to know what assets are included in your build and how much memory they need, just open the console right after you've created a build and press "Open Editor Log" button.
Notepad will open up (on windows). Just search (CTRL+F) for "***
" and you will find this line
***Player size statistics***
after that line you will find very detailed statistics about your build. - Included scenes and size of each - A list of all included assets - And much more...
The clean-up-problem is still there. We have almost the same problem in our project. I think an editor script could do that but you have to do the "used"-check yourself.
Finally here's a Unity-Forum-thread
edit
I've just wrote a little script that extracts the used assets from the editor log file.
It doesn't have much error checking and just search straight into the log. I guess if you create more than one build it will grab the first. You have to restart unity and create a new build to "update" the editor log content.
This script is written for Windows machines. It's just a little helper function. Now you can create a complete file list (via System.IO) and remove the used files.
But be careful: There are even files that should not be deleted!! (the Editor and plugin folder and propably some more)
Use this at your own risk
using UnityEngine; using UnityEditor; using System; using System.IO; using System.Collections; using System.Collections.Generic;
public class UsedAssets {
public static List<string> GetList()
{
List<string> result = new List<string>();
string LocalAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string UnityEditorLogfile = LocalAppData + "\\Unity\\Editor\\Editor.log";
try
{
// Have to use FileStream to get around sharing violations!
FileStream FS = new FileStream(UnityEditorLogfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
StreamReader SR = new StreamReader(FS);
string line;
while (!SR.EndOfStream && !(line = SR.ReadLine()).Contains("***Player size statistics***"));
while (!SR.EndOfStream && !(line = SR.ReadLine()).Contains("Used Assets,"));
while (!SR.EndOfStream && (line = SR.ReadLine()) != "")
{
line = line.Substring(line.IndexOf("% ") + 2);
result.Add(line);
}
}
catch (Exception E)
{
Debug.LogError("Error: " + E);
}
return result;
}
}
Thanks a lot for your answer! :D Unfortunately that doesn't solve the clean-up problem in a confortable manner, but at least now I know that it must be done manually, so let's embrace our patience and work it out! :)
I've added a simple function to extract the used file list from the editor.log file. $$anonymous$$aybe you can use it to sort out the unused files.
is it possible to make this output a list of unused items? Searching for 15000 asset names to see if they have been used would be painful to say the least.
Thanks
The only way would be to create the used-asset list and then use `System.IO` to get all files in your asset folder and subtract the used assets from all assets. But again be careful when deleting stuff! There might be some assets (like editor script and some other stuff) that aren't included in your build but are used else where. When creating your file-list you should exclude all "editor" folders.
Answer by Dougomite · May 22, 2013 at 05:33 PM
Couldn't you select all the scenes being used in your project. Right click and select export. That should show you a list of all files that have dependencies with those scenes, meaning all the files actually being used. Export that, then import it into a fresh project. You should then have only the files that are being used. At which point I guess you could delete the old project and all those unused assets along with it.
This seems like a decent solution, and I'm going to try it in addition to the Clean Up script in the above answer.
One thing to keep in $$anonymous$$d is you have to select your scene(s), right click "select dependencies", scroll down to make sure the scene(s) are still selected (or CTRL+click to add them back to the selection), and then export to a package.
@Dougomite: this answer works for me, mostly.
Not included when exporting the package is anything in the Standard Assets folder, in my case the Popup.cs file I used for my GUI (found on the wiki, linked below for reference/convenience/props to the author).
Luckily it was just the one script in my case, and it was easy enough to copy it over from the original project. Just something to keep in $$anonymous$$d for those who choose to go this route.
Hmmm, this also seems like it grabs a few things that aren't used. Not sure why that's happening, but either way the project folder is $$anonymous$$UCH cleaner.
for a creative solution. But watch out, assets retrieved via Resources.Load won't be in there, so that's "Standard Assets" + "Resources" that you need to copy manually so far. Plus anything your $$anonymous$$m wants in the project but hasn't yet used.
Worked for me. Still puzzled how the exported package was only 7.3 $$anonymous$$Bs while even my assets alone are over 25 $$anonymous$$B.
Answer by KristianHJ · Feb 15, 2012 at 01:08 PM
Created a tool on the asset store that automates the process. Lists all unused assets by type. Also lists the used files by filesize, making it easy to optimize buildsize.
Great! This was just what I needed. Consider putting it on the Unity store! :-)
Seems the link was outdated. You can still find it here Link to asset store
Answer by AvPerov · Jul 08, 2021 at 12:26 PM
Dependencies-Hunter can help you with the task of finding unused assets in your project. It's free and open-source.
Answer by achimmihca · Jan 02, 2018 at 07:45 PM
I also wanted to clear unused assets. I created a few scripts to show (un-)used assets based on the works from https://gist.github.com/karl-/4076464 What it does is read the unity build log to find the assets that are really needed and thus also the assets that are unused. The used and unused assets that are displayed can be filtered simply by selecting a folder in the project view. Works for me using Unity 5.5.0f3.
This seems that might do the work for me! Do you have a readme file to use this?
I created a git repo and added a description. See https://github.com/achimmihca/Unity3DBuildInfoWindowFindUnusedAssets
Your answer
Follow this Question
Related Questions
Remote access of Unity Asset Server? 3 Answers
Why does building bundles cause unload unused assets to be called? 1 Answer
What is the best way to understand a new unity project? 2 Answers
Access assets from project window through code 1 Answer
Do I have to commit the UnityTestTools to the repo? 1 Answer