Skip to content

Loading Assets

Jack Burkhardt edited this page Mar 26, 2024 · 4 revisions

We have an asset loading system which should make it easy to get the things you need at runtime without fussing over paths and casting. It is built upon Unity's Addressables package.

This means you do not (and should not) need to use the Resources or StreamingAssets folders anymore! Yay!

But first: making assets addressable

The first step is to make an asset Addressable. You can do so by following the instructions here. I recommend having a folder under Assets where you can organize all of your Addressables, and have created one called RuntimeAssets. Feel free to use it or your own system.

Use the Addressables Groups window to manage your groups and Addressable assets. To open the window, go to 1Window > Asset Management > Addressables > Groups`.

Loading assets (for real)

Now say you want to load this in game. There is one function you can call:

AddressableLoader.RequestLoad<T>(string address, Action<T> callback)
or
AddressableLoader.RequestLoad<T>(AssetReference reference, Action<T> callback)

You simply provide the Type (T) of the object you want to load (Sprite, AudioClip, Text, etc) and an address or reference.

AssetReferences offer a user interface (UI) compatible way to use Addressable assets. You can include AssetReference fields in MonoBehaviour and ScriptableObject classes. Then, you can assign assets to them in the Unity Editor either by dragging an Addressable asset into the AssetReference field in the Inspector window, or using the object picker dialog.

The Action is a function that is called when the object is done loading.

Clone this wiki locally