Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

How to find large files that is used and referenced in your Unity project

Posted on May 15, 2025May 16, 2025 by Habibie

I will share a script that will list top biggest files referenced and used in your Unity project so you can optimize these files.

Here is the script: FindReferencedLargeAssets

using UnityEditor;
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
using System.IO;

public class FindReferencedLargeAssets : EditorWindow
{
    [MenuItem("Tools/Find Referenced Large Assets")]
    public static void ShowWindow()
    {
        // Get all referenced assets
        HashSet<string> referencedPaths = GetReferencedAssetPaths();

        // Filter large assets (>1MB) and sort by size
        var largeReferencedAssets = AssetDatabase.GetAllAssetPaths()
            .Where(path => 
                !path.StartsWith("Assets/Editor") && 
                !path.StartsWith("Assets/StreamingAssets") &&
                referencedPaths.Contains(path) // Only referenced assets
            )
            .Select(path => new 
            {
                Path = path,
                Size = (new FileInfo(path)).Length / 1024 / 1024f // Size in MB
            })
            .Where(asset => asset.Size > 1) // Show files >1MB
            .OrderByDescending(asset => asset.Size)
            .Take(20); // Top 20 largest referenced files

        // Log results
        Debug.Log("=== LARGEST REFERENCED ASSETS (USED IN GAME) ===");
        foreach (var asset in largeReferencedAssets)
        {
            Debug.Log($"{asset.Path} - {asset.Size:F2} MB");
        }
    }

    // Get all asset paths referenced in scenes, prefabs, or Resources
    private static HashSet<string> GetReferencedAssetPaths()
    {
        HashSet<string> referencedPaths = new HashSet<string>();

        // 1. Check all scenes and prefabs
        string[] allScenePaths = AssetDatabase.FindAssets("t:Scene")
            .Select(guid => AssetDatabase.GUIDToAssetPath(guid))
            .ToArray();
        
        string[] allPrefabPaths = AssetDatabase.FindAssets("t:Prefab")
            .Select(guid => AssetDatabase.GUIDToAssetPath(guid))
            .ToArray();

        // 2. Find dependencies (recursively)
        foreach (string path in allScenePaths.Concat(allPrefabPaths))
        {
            string[] dependencies = AssetDatabase.GetDependencies(path, recursive: true);
            foreach (string dependency in dependencies)
            {
                referencedPaths.Add(dependency);
            }
        }

        // 3. Include everything in "Resources" folders (since they can be loaded dynamically)
        string[] resourcesAssets = AssetDatabase.FindAssets("", new[] { "Assets/Resources" })
            .Select(guid => AssetDatabase.GUIDToAssetPath(guid))
            .ToArray();
        
        foreach (string resourcePath in resourcesAssets)
        {
            referencedPaths.Add(resourcePath);
        }

        return referencedPaths;
    }
}

To run the script, go to tool menu and click the Find Referenced Large Assets inside it. Make sure you have this script inside Editor folder (make it if you don’t have).

There is also a pro version, which is a paid product. Get it here: https://creativeshop.ciihuy.com/product/large-assets-finder-script-by-ciihuycom/

Or get it from itch.io: https://ciihuycom.itch.io/large-assets-finder-script-by-ciihuycom

Post Views: 537
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme