I’m looking into addressables for our loading process, and I’d like to know if there was a way in the API to get the dependencies of an addressable asset.
While there is a way to download in advance the dependencies of an addressable, I can’t find a way to infer from this the list of assets effectively downloaded. (edit : see below)
I’d like to get this list from an editor script, as it would be useful for our build process.
Edit : I manageed to get the dependencies working in editor (using
Addressables.LoadResourceLocationsAsync(asset); to which I supplied the wrong key before).
But it’s not working in the editor, from what I gathered the Addressable system cannot init in edit mode)
Addressables.LoadResourceLocationsAsync(asset) doesn’t give a list of dependencies. It just returns the items that are referenced by the given key.
Edit: To clarify what I am looking for. I want to be able to know which bundles, not specific assets, will be downloaded when I do DownloadDependenciesAsync("myAsset")
And I need to write an editor script that will spit out that information
@BrokenAngel it sounds like you are having a different issue, and you just need to use DownloadDependenciesAsync("myAsset") which will download everything required to load whatever key you put in.
But I need to know which key is, and where I can get those keys ? since I want the application dynamically downloading all the “keys” I need in the server.
If I’m understanding you correctly, you want to know the names of the bundles that contain the dependencies for a given key.
Addressables.LoadResourceLocationsAsync(key) is half-way to what you’re looking for. Try this:
public IEnumerator GetDependencies(string key)
{
var locs = Addressables.LoadResourceLocationsAsync(key);
while (!locs.IsDone) yield return null;
foreach (var loc in locs.Result)
foreach (var dep in loc.Dependencies)
Debug.Log($"dep.PrimaryKey = {dep.PrimaryKey}");
}
The locs.Result is a list, but should only contain 1 variable. loc.Dependencies returns a list of the bundle names containing your key’s dependencies. The bundle names include folder paths if your bundle structure uses folders (ex: folder/folder/dependency.bundle) This list also includes the bundle for your key.
I’m using Addressables 1.5.0. I’m not entirely sure when this language became available.
EDIT: Don’t forget to load your content catalog. I didn’t include that step in my example.
And I take it you have haven’t tried AssetDatabase.GetDependencies? In my editor script, I use it in conjunction with AssetDatabase.GetAssetPath to look something like this:
Indeed I haven’t. I was so focused on getting the infos froms adressabels/bundles that I didn’t explore the AssetDatabase side.
I ended up catching what we were looking for as far as dependancies for now via reflection, but I’ll explore that possibility for the next refactor, thanks for pointing it out.
This is the code I came up with to accomplish my goal.
My goal is to be able to give an addressable key, which could be an address or label, and the end result would be a list of the bundles that would be needed to be able to load that addressable. This gives the literal bundle name of the built bundles.
I didn’t really go through this to pull out my specific needs. But i don’t think theres much specific to me in this.
private static List<string> GetDependenciesForKey(string addressablesKey)
{
var dependenciesList = new List<string>();
// If this is a label, we want to go and grab all the assets with that label, either way we want to start going through all the entries
AddressableAssetSettings aaSettings = AddressableAssetSettingsDefaultObject.Settings;
var assetsToCheckList = new List<string>();
foreach (AddressableAssetGroup addressableGroup in aaSettings.groups)
{
foreach (AddressableAssetEntry groupEntry in addressableGroup.entries)
{
// We check to see if the key is a label for any assets or if the key is an address of anything
// If it is, we add it to our assets to check list so we can use those to build our dependencies
if (groupEntry.address == addressablesKey || groupEntry.labels.Contains(addressablesKey))
{
if (!assetsToCheckList.Contains(groupEntry.AssetPath))
assetsToCheckList.Add(groupEntry.AssetPath);
// Lets create the bundle file name for whatever asset this is a part of now
string bundleFileName = GetBundleFileName(groupEntry);
if (!dependenciesList.Contains(bundleFileName))
dependenciesList.Add(bundleFileName);
}
}
}
foreach (string assetPath in assetsToCheckList)
{
List<string> childDependencies = GetAddressableDependenciesByPath(assetPath);
dependenciesList = dependenciesList.Union(childDependencies).ToList();
}
return dependenciesList;
}
private static List<string> GetAddressableDependenciesByPath(string filePath)
{
AddressableAssetSettings aaSettings = AddressableAssetSettingsDefaultObject.Settings;
string[] deps = AssetDatabase.GetDependencies(filePath);
var dependenciesList = new List<string>();
foreach (string dep in deps)
{
string guid = AssetDatabase.AssetPathToGUID(dep);
AddressableAssetEntry entry = aaSettings.FindAssetEntry(guid);
if (entry == null)
continue;
string bundleFileName = GetBundleFileName(entry);
if (!dependenciesList.Contains(bundleFileName))
dependenciesList.Add(bundleFileName);
}
return dependenciesList;
}
Hate to necro a sorta old post, but seems worth adding here instead of making a new post.
Would be nice if the dependencies of a group could be displayed in the editor out of the box so that non-developers (aka level designers) could see how many bundles the map they are working on will have to download while working on it.
Going to create an internal tool to do this for my company, just figured id suggest it here as well.