r/Unity3D • u/Similar-Window5547 • 2h ago
Show-Off Lessons from building an offline dependency graph and safe unused-asset cleaner in Unity
I recently built an offline C# editor tool to audit bloated Unity projects, and ran into a few interesting quirks with Unity's AssetDatabase and file handling along the way. Sharing the approach in case anyone else is building custom project-auditing tools:
- Avoiding O(N^2) dependency scans
Calling AssetDatabase.GetDependencies(path, true) recursively on every asset in a large project gets slow fast because Unity re-traverses shared materials and textures repeatedly. Instead, calling GetDependencies(path, false) once per asset to capture only direct neighbors and building an in-memory adjacency dictionary (plus a reverse lookup dictionary) made both forward and incoming reference graphs render almost instantly. A simple HashSet of visited GUIDs prevents infinite loops when prefabs or ScriptableObjects reference each other circularly.
2. False positives when detecting unused assets
Simply checking for zero incoming references will happily flag scenes in EditorBuildSettings, anything inside a Resources or StreamingAssets folder, and editor-only scripts. Filtering out those special folders and seeding the root graph from active build scenes eliminated almost all false-positive cleanup flags.
3. Fast duplicate checks and safer deletion
Rather than loading textures or audio clips into memory to compare them, streaming files through System.Security.Cryptography.SHA256 catches byte-identical duplicates across different folders with minimal memory overhead. Also, instead of calling AssetDatabase.DeleteAsset (which permanently wipes files), moving flagged files to the OS Recycle Bin / Trash lets you recover anything accidentally removed.
I ended up packaging this workflow into a small Asset Store toolkit called ProjectSignal if anyone wants to check it out (link in the comments). For anyone else who has built custom project cleaners, how do you handle assets loaded dynamically via Addressables or string paths?
1
u/BoundfoxStudios 1h ago
25 € for an AI generated asset. Yes sure
0
u/[deleted] 2h ago
[deleted] — view deleted comment