| | |

Speeding up Addressable Assets Loading

Are you using Addressable assets in your project? Is loading very slow, especially while pressing Play in the Editor?

Make sure you are loading a list of Tasks and running them in parallel instead of individually waiting for each Task to finish.

// get locations of all Addressables
var locations = await Addressables.LoadResourceLocationsAsync(label).Task;

// this list will store all the tasks
// NOTE: change AudioClip to the type of object you will be reading e.g. TextAsset, GameObject (for Prefabs), etc.
List<Task<AudioClip>> loadAudioClipTasks = new List<Task<AudioClip>>();

foreach (var location in locations) {
    // queue up all the tasks to be run in parallel
    loadAudioClipTasks.Add(Addressables.LoadAssetAsync<AudioClip>(location).Task);
}

// load all the assets - each task will run in parallel
var loadedAssets = await Task.WhenAll(loadAudioClipTasks)
foreach (var asset in loadedAssets) {
    Debug.Log("Loaded " + asset.name);
    AudioAssets.Add(asset);
}

NOTE: You can also put the WhenAll directly in the foreach() loop to avoid creating another temporary variable.

Similar Posts

Leave a Reply