- Home /
Cleaning Project of unused scripts
I am cleaning my project and want to get rid of scripts that are not used. Is there a way to identify what scripts are used and which are not?
I too would like to know if a solution exist for this. I made a mess of my scripts folder structures and got scripts everywhere.
Answer by DiegoSLTS · May 27, 2015 at 03:49 PM
If you're using Unity 5 or have a pro license in older Unity versions you can select all your scenes in the project window and select to export them as a package. Unity will show you a list of all assets that are referenced in those scenes (and by prefabs used in the scenes), so you can check there if a script from your project is being used.
Another option could be to right click in an asset and select "Find references in scene" but it's slower and you have to check on each scene, one by one.
Does this include Scripts which aren't directly assigned to any Prefab, but only via Script, e.g. with the AddComponent()-$$anonymous$$ethod or any Static Classes?
If not, going this way to detect unused scripts might be problematic.
This doesn't work for scripts. Unity can gather dependencies to assets like textures and prefabs and will correctly exclude unused ones, but it can't possibly know if you need a certain script. How would it? If a script is not referenced by any scene, it could still be referenced somewhere in code. Now Unity could parse all script files and do individual compilation passes to find all references and also check for platform dependent compilation and so on, but there are probably a dozen other things, which could go wrong, like when you use reflection. Sadly, there is no magic automated way of knowing which scripts are being used. If you know your project, you can probably write a tool based on assumptions like, you're not using reflection or only using $$anonymous$$onoBehaviour etc, but it will still be tricky.
Answer by Gotlight · Aug 07, 2020 at 11:46 AM
Hi @diggerjohn @dreg_master @jwulf @Xarbrough ! There's a tool made especially for getting rid of unused assets and scenes in a project. I guarantee it's the easiest way possible without losing context :-)
https://assetstore.unity.com/packages/tools/utilities/asset-cleaner-pro-clean-find-references-167990
It allows you to:
Hunt down the unused Assets and Scenes (not only scripts) without any need to generate build
The unused assets are shown directly in your Project view (regarding the scripts, see below)
Check the dependencies/references for those which are used somewhere (supports Nested Prefabs and all asset types).
One note regarding the Scripts themselves - those aren't shown red in the Editor as it's not possible to know whether the script isn't used outside of Unity. However there's a way we're hunting the unused scripts down ourselves.
There are 3 types of scripts important for this topic:
1. Non-related to Unity serialization
2. Derived from MonoBehavior
3. Derived from ScriptableObject
Because of #1, we need to be careful with stating whether a certain script could or could not be removed.
We ourselves are using the Asset Cleaner for the purpose of cleaning scripts the following way (step by step):
In Asset Cleaner, we're selecting the given script and checking its usages.
If there are some (see example on screenshot below), we remove the linkages manually
If there are none, we remove it.
Asset Cleaner is capable of showing the usages within Unity:
For MonoBehavior-derived classes: Usages in prefabs and scenes (after unfolding one, see screenshot above) are shown
For ScriptableObject-derived classes: All script instances will be shown
In a nutshell:
Any question you have, you'll get a quick answer:-) You can ask here, via email:
gamedevtools.assetstore@gmail.com or via Telegram chat:
https://t.me/joinchat/BdWObBk5PxjNALiRSXp7Vw
Thanks and looking forward to seeing you among our happy users:)
Denis from Gamedevtools team
Your answer
Follow this Question
Related Questions
Organize Inspector Better? 1 Answer
Any way to stop texture lookup wiping material from prefab? 0 Answers
What does "Clean All" do? 1 Answer
baked animation cleanup 0 Answers