Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


LoadableObjectId

A low-level reference to an object within an asset, used to pull assets into a content directory build, and for on-demand loading.
Read time 2 minutesLast updated 4 days ago

Definition

public struct LoadableObjectId : IEquatable<LoadableObjectId>

Remarks

LoadableObjectId is the underlying reference type used by Loadable<T>. It contains the information needed to identify and load a specific object from built content.
In the Editor, use LoadableObjectIdEditorUtility to create LoadableObjectIds. Typically these are serialized as part of Loadable<T> fields on classes derived from ScriptableObject or MonoBehaviour. You can also use LoadableObjectId directly as a field type in a ScriptableObject or MonoBehaviour, and then create Loadable<T> objects on the fly as needed.
Using LoadableObjectId directly suits a root asset that acts as a library of assets shared by several components. Because LoadableObjectId has no load or release methods of its own, it makes clear that each caller constructs its own Loadable<T> and owns the lifetime of the object it loads.
LoadableObjectId has no generic type parameter, so it can reference any Object. Add your own validation if a field must only accept a specific type.
When those objects are built as part of a content directory, the assets referenced by the LoadableObjectId are recursively pulled into the build output. At runtime, the ContentLoadManager resolves LoadableObjectIds to the correct built content as long as it is part of the currently registered content directories.
A LoadableObjectId is only supported in content built with BuildPipeline.BuildContentDirectory. If a LoadableObjectId is found in serialized data during a Player or AssetBundle build, the reference is set to null in the build output and an error is logged. Suppress this error with BuildOptions.SuppressLoadableErrors for Player builds or BuildAssetBundleOptions.SuppressLoadableErrors for AssetBundle builds.

Examples

using Unity.Loading;using UnityEngine;namespace BuildDocExamples{ // Example showing how LoadableObjectId is used in practice [CreateAssetMenu] public class Catalog : ScriptableObject { public LoadableObjectId iconId; } public class LoadableObjectId_Example { public void ExampleUsage() { // In the editor, assign iconId via LoadableObjectIdEditorUtility.CreateLoadableObjectId(iconTexture); Catalog catalog = ScriptableObject.CreateInstance<Catalog>(); // At runtime, bridge LoadableObjectId to Loadable<T> for the runtime API: Loadable<Texture2D> iconLoadable = new Loadable<Texture2D>(catalog.iconId); iconLoadable.Load(); // Use iconLoadable.Target... iconLoadable.Release(); } }}

Properties

Property

Description

IsValidTrue if this LoadableObjectId is initialized with valid data.

Methods

Method

Description

ToStringReturns a string representation of this LoadableObjectId.