Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

LoadableObjectId

struct in Unity.Loading

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

A low-level reference to an object within an asset, used to pull assets into a content directory build, and for on-demand loading.

LoadableObjectId is the underlying reference type used by Loadable<T0>. 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<T0> 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<T0> objects on the fly as needed.

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.

Additional resources: Loadable<T0>, LoadableObjectIdEditorUtility

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
IsValid True if this LoadableObjectId is initialized with valid data.

Public Methods

Method Description
ToString Returns a string representation of this LoadableObjectId.