Class Addressables
Entry point for Addressable API, this provides a simpler interface than using ResourceManager directly as it assumes string address type.
Inheritance
Namespace: UnityEngine.AddressableAssets
Syntax
public static class Addressables
Fields
kAddressablesRuntimeDataPath
The name of the PlayerPrefs value used to set the path to load the addressables runtime data file.
Declaration
public const string kAddressablesRuntimeDataPath = "AddressablesRuntimeDataPath"
Field Value
Type | Description |
---|---|
System.String |
Properties
BuildPath
The path used by the Addressables system for its initialization data.
Declaration
public static string BuildPath { get; }
Property Value
Type | Description |
---|---|
System.String |
InitializationOperation
Initialization operation. You can register a callback with this if you need to run code after Addressables is ready. Any requests made before this operaton completes will automatically cahin to its result.
Declaration
public static IAsyncOperation<IResourceLocator> InitializationOperation { get; }
Property Value
Type | Description |
---|---|
IAsyncOperation<IResourceLocator> |
ResourceLocators
Gets the list of configured IResourceLocator objects. Resource Locators are used to find IResourceLocation objects from user-defined typed keys.
Declaration
public static IList<IResourceLocator> ResourceLocators { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IList<IResourceLocator> | The resource locators list. |
ResourceManager
Declaration
public static ResourceManager ResourceManager { get; }
Property Value
Type | Description |
---|---|
ResourceManager |
RuntimePath
The path used by the Addressables system to load initialization data.
Declaration
public static string RuntimePath { get; }
Property Value
Type | Description |
---|---|
System.String |
StreamingAssetsSubFolder
The subfolder used by the Addressables system for its initialization data.
Declaration
public static string StreamingAssetsSubFolder { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
DownloadDependencies(IList<Object>, Addressables.MergeMode)
Downloads dependencies of assets marked with the specified labels and addresses.
Declaration
public static IAsyncOperation DownloadDependencies(IList<object> keys, Addressables.MergeMode mode)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<System.Object> | keys | The keys of the assets to load dependencies for. |
Addressables.MergeMode | mode | Method for merging the results of key matches. See Addressables.MergeMode for specifics |
Returns
Type | Description |
---|---|
IAsyncOperation | The IAsyncOperation for the dependency load. |
DownloadDependencies(Object)
Downloads dependencies of assets marked with the specified label or address.
Declaration
public static IAsyncOperation DownloadDependencies(object key)
Parameters
Type | Name | Description |
---|---|---|
System.Object | key | The key of the asset(s) to load dependencies for. |
Returns
Type | Description |
---|---|
IAsyncOperation | The IAsyncOperation for the dependency load. |
GetDownloadSize(Object)
Asynchronously loads only the dependencies for the specified key
.
Declaration
public static IAsyncOperation<long> GetDownloadSize(object key)
Parameters
Type | Name | Description |
---|---|---|
System.Object | key | key for which to load dependencies. |
Returns
Type | Description |
---|---|
IAsyncOperation<System.Int64> | An async operation that will complete when all individual async load operations are complete. |
Initialize()
Initialize Addressables system. This method will automatically be called at startup unless ADDRESSABLES_DISABLE_AUTO_INITIALIZATION is defined as a script conditional in the player settings. If ADDRESSABLES_DISABLE_AUTO_INITIALIZATION is set and a request is made, this method will also be called then. It is safe to call this method mutliple times as it will only initialize once.
Declaration
public static IAsyncOperation<IResourceLocator> Initialize()
Returns
Type | Description |
---|---|
IAsyncOperation<IResourceLocator> | IAsync operation for initialization. The result of the operation is the IResourceLocator that was loaded. |
Instantiate(Object, Transform, Boolean)
Instantiate single object.
Declaration
public static IAsyncOperation<GameObject> Instantiate(object key, Transform parent = null, bool instantiateInWorldSpace = false)
Parameters
Type | Name | Description |
---|---|---|
System.Object | key | The key of the location of the Object to instantiate. |
Transform | parent | Parent transform for instantiated object. |
System.Boolean | instantiateInWorldSpace | Option to retain world space when instantiated with a parent. |
Returns
Type | Description |
---|---|
IAsyncOperation<GameObject> |
Instantiate(Object, InstantiationParameters)
Instantiate single object.
Declaration
public static IAsyncOperation<GameObject> Instantiate(object key, InstantiationParameters instantiateParameters)
Parameters
Type | Name | Description |
---|---|---|
System.Object | key | The key of the location of the Object to instantiate. |
InstantiationParameters | instantiateParameters | Parameters for instantiation. |
Returns
Type | Description |
---|---|
IAsyncOperation<GameObject> |
Instantiate(Object, Vector3, Quaternion, Transform)
Instantiate single object.
Declaration
public static IAsyncOperation<GameObject> Instantiate(object key, Vector3 position, Quaternion rotation, Transform parent = null)
Parameters
Type | Name | Description |
---|---|---|
System.Object | key | The key of the location of the Object to instantiate. |
Vector3 | position | The position of the instantiated object. |
Quaternion | rotation | The rotation of the instantiated object. |
Transform | parent | Parent transform for instantiated object. |
Returns
Type | Description |
---|---|
IAsyncOperation<GameObject> |
Instantiate(IResourceLocation, Transform, Boolean)
Instantiate single object.
Declaration
public static IAsyncOperation<GameObject> Instantiate(IResourceLocation location, Transform parent = null, bool instantiateInWorldSpace = false)
Parameters
Type | Name | Description |
---|---|---|
IResourceLocation | location | The location of the Object to instantiate. |
Transform | parent | Parent transform for instantiated object. |
System.Boolean | instantiateInWorldSpace | Option to retain world space when instantiated with a parent. |
Returns
Type | Description |
---|---|
IAsyncOperation<GameObject> |
Instantiate(IResourceLocation, InstantiationParameters)
Instantiate object.
Declaration
public static IAsyncOperation<GameObject> Instantiate(IResourceLocation location, InstantiationParameters instantiateParameters)
Parameters
Type | Name | Description |
---|---|---|
IResourceLocation | location | The location of the Object to instantiate. |
InstantiationParameters | instantiateParameters | Parameters for instantiation. |
Returns
Type | Description |
---|---|
IAsyncOperation<GameObject> |
Instantiate(IResourceLocation, Vector3, Quaternion, Transform)
Instantiate single object.
Declaration
public static IAsyncOperation<GameObject> Instantiate(IResourceLocation location, Vector3 position, Quaternion rotation, Transform parent = null)
Parameters
Type | Name | Description |
---|---|---|
IResourceLocation | location | The location of the Object to instantiate. |
Vector3 | position | The position of the instantiated object. |
Quaternion | rotation | The rotation of the instantiated object. |
Transform | parent | Parent transform for instantiated object. |
Returns
Type | Description |
---|---|
IAsyncOperation<GameObject> |
InstantiateAll(IList<IResourceLocation>, Action<IAsyncOperation<GameObject>>, InstantiationParameters)
Instantiate multiple objects.
Declaration
public static IAsyncOperation<IList<GameObject>> InstantiateAll(IList<IResourceLocation> locations, Action<IAsyncOperation<GameObject>> callback, InstantiationParameters instantiateParameters)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<IResourceLocation> | locations | The locations of the objects to instantiate. |
System.Action<IAsyncOperation<GameObject>> | callback | This callback will be invoked once for each object that is instantiated. |
InstantiationParameters | instantiateParameters | Parameters for instantiation. |
Returns
Type | Description |
---|---|
IAsyncOperation<System.Collections.Generic.IList<GameObject>> |
InstantiateAll(Object, Action<IAsyncOperation<GameObject>>, Transform, Boolean)
Instantiate multiple objects.
Declaration
public static IAsyncOperation<IList<GameObject>> InstantiateAll(object key, Action<IAsyncOperation<GameObject>> callback, Transform parent = null, bool instantiateInWorldSpace = false)
Parameters
Type | Name | Description |
---|---|---|
System.Object | key | The key of the locations of the objects to instantiate. |
System.Action<IAsyncOperation<GameObject>> | callback | Callback Action that is called per load operation |
Transform | parent | Parent transform for instantiated objects. |
System.Boolean | instantiateInWorldSpace | Option to retain world space when instantiated with a parent. |
Returns
Type | Description |
---|---|
IAsyncOperation<System.Collections.Generic.IList<GameObject>> |
InstantiateAll(Object, Action<IAsyncOperation<GameObject>>, InstantiationParameters)
Instantiate multiple objects.
Declaration
public static IAsyncOperation<IList<GameObject>> InstantiateAll(object key, Action<IAsyncOperation<GameObject>> callback, InstantiationParameters instantiateParameters)
Parameters
Type | Name | Description |
---|---|---|
System.Object | key | The key of the location of the objects to instantiate. |
System.Action<IAsyncOperation<GameObject>> | callback | This callback will be invoked once for each object that is instantiated. |
InstantiationParameters | instantiateParameters | Parameters for instantiation. |
Returns
Type | Description |
---|---|
IAsyncOperation<System.Collections.Generic.IList<GameObject>> |
LoadAsset<TObject>(Object)
Load a single asset
Declaration
public static IAsyncOperation<TObject> LoadAsset<TObject>(object key)
where TObject : class
Parameters
Type | Name | Description |
---|---|---|
System.Object | key | The key of the location of the asset. |
Returns
Type | Description |
---|---|
IAsyncOperation<TObject> |
Type Parameters
Name | Description |
---|---|
TObject |
LoadAsset<TObject>(IResourceLocation)
Load a single asset
Declaration
public static IAsyncOperation<TObject> LoadAsset<TObject>(IResourceLocation location)
where TObject : class
Parameters
Type | Name | Description |
---|---|---|
IResourceLocation | location | The location of the asset. |
Returns
Type | Description |
---|---|
IAsyncOperation<TObject> |
Type Parameters
Name | Description |
---|---|
TObject |
LoadAssets<TObject>(IList<Object>, Action<IAsyncOperation<TObject>>, Addressables.MergeMode)
Load mutliple assets
Declaration
public static IAsyncOperation<IList<TObject>> LoadAssets<TObject>(IList<object> keys, Action<IAsyncOperation<TObject>> callback, Addressables.MergeMode mode)
where TObject : class
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<System.Object> | keys | List of keys for the locations. |
System.Action<IAsyncOperation<TObject>> | callback | Callback Action that is called per load operation. |
Addressables.MergeMode | mode | Method for merging the results of key matches. See Addressables.MergeMode for specifics |
Returns
Type | Description |
---|---|
IAsyncOperation<System.Collections.Generic.IList<TObject>> |
Type Parameters
Name | Description |
---|---|
TObject |
LoadAssets<TObject>(IList<IResourceLocation>, Action<IAsyncOperation<TObject>>)
Load multiple assets
Declaration
public static IAsyncOperation<IList<TObject>> LoadAssets<TObject>(IList<IResourceLocation> locations, Action<IAsyncOperation<TObject>> callback)
where TObject : class
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<IResourceLocation> | locations | The locations of the assets. |
System.Action<IAsyncOperation<TObject>> | callback | Callback Action that is called per load operation. |
Returns
Type | Description |
---|---|
IAsyncOperation<System.Collections.Generic.IList<TObject>> |
Type Parameters
Name | Description |
---|---|
TObject |
LoadAssets<TObject>(Object, Action<IAsyncOperation<TObject>>)
Load mutliple assets
Declaration
public static IAsyncOperation<IList<TObject>> LoadAssets<TObject>(object key, Action<IAsyncOperation<TObject>> callback)
where TObject : class
Parameters
Type | Name | Description |
---|---|---|
System.Object | key | Key for the locations. |
System.Action<IAsyncOperation<TObject>> | callback | Callback Action that is called per load operation. |
Returns
Type | Description |
---|---|
IAsyncOperation<System.Collections.Generic.IList<TObject>> |
Type Parameters
Name | Description |
---|---|
TObject |
LoadContentCatalog(String, String)
Additively load catalogs from runtime data. The settings are not used.
Declaration
public static IAsyncOperation<IResourceLocator> LoadContentCatalog(string catalogPath, string providerSuffix = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | catalogPath | The path to the runtime data. |
System.String | providerSuffix | This value, if not null or empty, will be appended to all provider ids loaded from this data. |
Returns
Type | Description |
---|---|
IAsyncOperation<IResourceLocator> | IAsync operation for initialization. |
LoadScene(Object, LoadSceneMode)
Load scene.
Declaration
public static IAsyncOperation<Scene> LoadScene(object key, LoadSceneMode loadMode = null)
Parameters
Type | Name | Description |
---|---|---|
System.Object | key | The key of the location of the scene to load. |
LoadSceneMode | loadMode | Scene load mode. |
Returns
Type | Description |
---|---|
IAsyncOperation<Scene> |
LoadScene(IResourceLocation, LoadSceneMode)
Load scene.
Declaration
public static IAsyncOperation<Scene> LoadScene(IResourceLocation location, LoadSceneMode loadMode = null)
Parameters
Type | Name | Description |
---|---|---|
IResourceLocation | location | The location of the scene to load. |
LoadSceneMode | loadMode | Scene load mode. |
Returns
Type | Description |
---|---|
IAsyncOperation<Scene> |
Log(String)
Debug.Log wrapper method that is contional on the LOG_ADDRESSABLES symbol definition. This can be set in the Player preferences in the 'Scripting Define Symbols'.
Declaration
[Conditional("ADDRESSABLES_LOG_ALL")]
public static void Log(string msg)
Parameters
Type | Name | Description |
---|---|---|
System.String | msg | The msg to log |
LogError(String)
Debug.LogError wrapper method.
Declaration
public static void LogError(string msg)
Parameters
Type | Name | Description |
---|---|---|
System.String | msg | The msg to log |
LogErrorFormat(String, Object[])
Debug.LogErrorFormat wrapper method.
Declaration
public static void LogErrorFormat(string format, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | The string with format tags. |
System.Object[] | args | The args used to fill in the format tags. |
LogException(IAsyncOperation, Exception)
Debug.LogException wrapper method.
Declaration
public static void LogException(IAsyncOperation op, Exception ex)
Parameters
Type | Name | Description |
---|---|---|
IAsyncOperation | op | |
System.Exception | ex |
LogFormat(String, Object[])
Debug.LogFormat wrapper method that is contional on the LOG_ADDRESSABLES symbol definition. This can be set in the Player preferences in the 'Scripting Define Symbols'.
Declaration
[Conditional("ADDRESSABLES_LOG_ALL")]
public static void LogFormat(string format, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | The string with format tags. |
System.Object[] | args | The args used to fill in the format tags. |
LogWarning(String)
Debug.LogWarning wrapper method.
Declaration
public static void LogWarning(string msg)
Parameters
Type | Name | Description |
---|---|---|
System.String | msg | The msg to log |
LogWarningFormat(String, Object[])
Debug.LogWarningFormat wrapper method.
Declaration
public static void LogWarningFormat(string format, params object[] args)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | The string with format tags. |
System.Object[] | args | The args used to fill in the format tags. |
RecordInstanceSceneChange(GameObject, Scene, Scene)
Notify the ResourceManager that a tracked instance has changed scenes so that it can be released properly when the scene is unloaded.
Declaration
public static void RecordInstanceSceneChange(GameObject gameObject, Scene previousScene, Scene currentScene)
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | The gameobject that is being moved to a new scene. |
Scene | previousScene | Previous scene for gameobject. |
Scene | currentScene | Current scene for gameobject. |
ReleaseAsset<TObject>(TObject)
Release asset.
Declaration
public static void ReleaseAsset<TObject>(TObject asset)
where TObject : class
Parameters
Type | Name | Description |
---|---|---|
TObject | asset | The asset to release. |
Type Parameters
Name | Description |
---|---|
TObject |
ReleaseInstance(GameObject, Single)
Release instantiated object.
Declaration
public static void ReleaseInstance(GameObject instance, float delay = 0F)
Parameters
Type | Name | Description |
---|---|---|
GameObject | instance | The instantiated object to release. |
System.Single | delay | The time delay in seconds to wait until releasing the instantiated object. If this value is less than 0, it will release immediately. |
ResolveInternalId(String)
Used to resolve a string using addressables config values
Declaration
public static string ResolveInternalId(string id)
Parameters
Type | Name | Description |
---|---|---|
System.String | id |
Returns
Type | Description |
---|---|
System.String |
UnloadScene(Scene)
Unload scene.
Declaration
public static IAsyncOperation<Scene> UnloadScene(Scene scene)
Parameters
Type | Name | Description |
---|---|---|
Scene | scene | The scene to unload. |
Returns
Type | Description |
---|---|
IAsyncOperation<Scene> |