Editor utilities for creating and converting LoadableObjectId values when authoring content.
LoadableObjectId is the low-level reference type used by Loadable{T} for on-demand object loading.
These methods convert between live Object instances and serialized loadable object IDs for content directory builds.
using Unity.Loading; using UnityEditor; using UnityEngine;
namespace BuildDocExamples { // Example showing how to use LoadableObjectIdEditorUtility to convert between Objects and LoadableObjectIds public class LoadableObjectIdEditorUtility_Example { public void ConvertObjectToLoadableObjectId() { // Load an asset from the AssetDatabase Texture2D iconTexture = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/Icon.png");
// Convert the Object to a LoadableObjectId LoadableObjectId iconId = LoadableObjectIdEditorUtility.CreateLoadableObjectId(iconTexture);
// Now iconId can be serialized on a ScriptableObject for content directory builds }
public void ConvertLoadableObjectIdToObject() { LoadableObjectId iconId = new LoadableObjectId(); // ... (iconId would typically be loaded from serialized data)
// Convert the LoadableObjectId back to an Object in the Editor Object obj = LoadableObjectIdEditorUtility.LoadableObjectIdToObject(iconId);
if (obj is Texture2D texture) { // Use the texture in the Editor Debug.Log($"Loaded texture: {texture.name}"); } } } }
| Method | Description |
|---|---|
| CreateLoadableObjectId | Creates a LoadableObjectId from a Object that can be used for on-demand loading. |
| LoadableObjectIdToObject | Retrieve the Object referenced by a LoadableObjectId. |
| TryDeconstructLoadableObjectId | Deconstructs a LoadableObjectId into its component parts: GUID, local file identifier, and file identifier type. |