Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

sylafcode commented Sep 2, 2020

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