Class Addressables
Entry point for Addressable API, this provides a simpler interface than using ResourceManager directly as it assumes string address type.
Inheritance
Inherited Members
Namespace: UnityEngine.AddressableAssets
Syntax
public static class Addressables
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
Declaration
public static IList<IResourceLocator> ResourceLocators { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IList<IResourceLocator> | The resource locators list. |
RuntimePath
The path used by the Addressables system to load initialization data.
Declaration
public static string RuntimePath { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
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<TObject>(IResourceLocation, InstantiationParameters)
Instantiate object.
Declaration
public static IAsyncOperation<TObject> Instantiate<TObject>(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<TObject> |
Type Parameters
Name | Description |
---|---|
TObject |
Instantiate<TObject>(IResourceLocation, Transform, Boolean)
Instantiate single object.
Declaration
public static IAsyncOperation<TObject> Instantiate<TObject>(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<TObject> |
Type Parameters
Name | Description |
---|---|
TObject |
Instantiate<TObject>(IResourceLocation, Vector3, Quaternion, Transform)
Instantiate single object.
Declaration
public static IAsyncOperation<TObject> Instantiate<TObject>(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<TObject> |
Type Parameters
Name | Description |
---|---|
TObject |
Instantiate<TObject>(Object, InstantiationParameters)
Instantiate single object.
Declaration
public static IAsyncOperation<TObject> Instantiate<TObject>(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<TObject> |
Type Parameters
Name | Description |
---|---|
TObject |
Instantiate<TObject>(Object, Transform, Boolean)
Instantiate single object.
Declaration
public static IAsyncOperation<TObject> Instantiate<TObject>(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<TObject> |
Type Parameters
Name | Description |
---|---|
TObject |
Instantiate<TObject>(Object, Vector3, Quaternion, Transform)
Instantiate single object.
Declaration
public static IAsyncOperation<TObject> Instantiate<TObject>(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<TObject> |
Type Parameters
Name | Description |
---|---|
TObject |
InstantiateAll<TObject>(IList<IResourceLocation>, Action<IAsyncOperation<TObject>>, InstantiationParameters)
Instantiate multiple objects.
Declaration
public static IAsyncOperation<IList<TObject>> InstantiateAll<TObject>(IList<IResourceLocation> locations, Action<IAsyncOperation<TObject>> callback, InstantiationParameters instantiateParameters)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<IResourceLocation> | locations | The locations of the objects to instantiate. |
System.Action<IAsyncOperation<TObject>> | 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<TObject>> |
Type Parameters
Name | Description |
---|---|
TObject |
InstantiateAll<TObject>(Object, Action<IAsyncOperation<TObject>>, InstantiationParameters)
Instantiate multiple objects.
Declaration
public static IAsyncOperation<IList<TObject>> InstantiateAll<TObject>(object key, Action<IAsyncOperation<TObject>> callback, InstantiationParameters instantiateParameters)
Parameters
Type | Name | Description |
---|---|---|
System.Object | key | The key of the location of the objects to instantiate. |
System.Action<IAsyncOperation<TObject>> | 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<TObject>> |
Type Parameters
Name | Description |
---|---|
TObject |
InstantiateAll<TObject>(Object, Action<IAsyncOperation<TObject>>, Transform, Boolean)
Instantiate multiple objects.
Declaration
public static IAsyncOperation<IList<TObject>> InstantiateAll<TObject>(object key, Action<IAsyncOperation<TObject>> 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<TObject>> | callback | |
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<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 |
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 |
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 |
Returns
Type | Description |
---|---|
IAsyncOperation<System.Collections.Generic.IList<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 = Addressables.MergeMode.None)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 | Merge method of locations. |
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 |
LoadCatalogsFromRuntimeData(String)
Additively load catalogs from runtime data. The settings are not used.
Declaration
public static IAsyncOperation<IResourceLocator> LoadCatalogsFromRuntimeData(string runtimeDataPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | runtimeDataPath | The path to the runtime data. |
Returns
Type | Description |
---|---|
IAsyncOperation<IResourceLocator> | IAsync operation for initialization. |
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> |
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> |
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. |
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. |
PreloadDependencies(IList<Object>, Action<IAsyncOperation<Object>>, Addressables.MergeMode)
Asynchronously loads only the dependencies for the specified list of keys.
Declaration
public static IAsyncOperation<IList<object>> PreloadDependencies(IList<object> keys, Action<IAsyncOperation<object>> callback, Addressables.MergeMode mode = Addressables.MergeMode.None)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<System.Object> | keys | List of keys for which to load dependencies. |
System.Action<IAsyncOperation<System.Object>> | callback | This callback will be invoked once for each object that is loaded. |
Addressables.MergeMode | mode |
Returns
Type | Description |
---|---|
IAsyncOperation<System.Collections.Generic.IList<System.Object>> | An async operation that will complete when all individual async load operations are complete. |
PreloadDependencies(Object, Action<IAsyncOperation<Object>>)
Asynchronously loads only the dependencies for the specified key.
Declaration
public static IAsyncOperation<IList<object>> PreloadDependencies(object key, Action<IAsyncOperation<object>> callback)
Parameters
Type | Name | Description |
---|---|---|
System.Object | key | key for which to load dependencies. |
System.Action<IAsyncOperation<System.Object>> | callback | This callback will be invoked once for each object that is loaded. |
Returns
Type | Description |
---|---|
IAsyncOperation<System.Collections.Generic.IList<System.Object>> | An async operation that will complete when all individual async load operations are complete. |
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(Object, Single)
Release instantiated object.
Declaration
public static void ReleaseInstance(object instance, float delay = 0F)
Parameters
Type | Name | Description |
---|---|---|
System.Object | 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. |
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> |