Skip to content

Instantly share code, notes, and snippets.

@rickyah
Last active September 10, 2020 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickyah/98e63d7c91d3ae06be38848a80a00c83 to your computer and use it in GitHub Desktop.
Save rickyah/98e63d7c91d3ae06be38848a80a00c83 to your computer and use it in GitHub Desktop.
Script to print all asset bundles of the project and its dependencies
[MenuItem("AssetBundles/Print all Asset Bundle names")]
static void PrintAssetBundlesToDebugConsole()
{
var sb = new StringBuilder();
var globalTimer = new Stopwatch();
var timer = new Stopwatch();
globalTimer.Start();
timer.Start();
var assetBundles = new List<string>(AssetDatabase.GetAllAssetBundleNames());
timer.Stop();
sb.AppendLine($"Retrieved list of Asset Bundles: {assetBundles.Count} [{timer.ElapsedMilliseconds /1000.0}s]");
timer.Reset();
foreach(var assetBundle in assetBundles)
{
bool recursive = true;
timer.Start();
var dependencies = AssetDatabase.GetAssetBundleDependencies(assetBundle, recursive);
timer.Stop();
sb.AppendLine($"{assetBundle} [{timer.ElapsedMilliseconds /1000.0}s]");
foreach(var dependency in dependencies)
{
sb.AppendLine($"\t{dependency}");
}
timer.Reset();
}
globalTimer.Stop();
sb.AppendLine($"Total elapsed time: [{globalTimer.ElapsedMilliseconds /1000.0}s]");
Debug.Log(sb.ToString());
}
@sylafcode
Copy link

Hey,

I also made this kind of code (started from Unity docs, then added the "GetAssetBundleDependencies" method),
I ended up using yours, but AssetDatabase.GetAssetBundleDependencies doesn't return a thing in my project.

(Even though some assets ARE linked to the assetBundle)

Does the script work fine with your project?

Best regards,
Sylafrs

@rickyah
Copy link
Author

rickyah commented Sep 10, 2020

Yep, it works con Unity 2018. Have you tried generating the assets once? Maybe Unity is using an internal database or something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment