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

LoadableObjectIdEditorUtility

class in UnityEditor

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

Editor utilities for creating and converting LoadableObjectId values when authoring content.

LoadableObjectId is the low-level reference type used by Loadable<T0> for on-demand object loading. These methods convert between live Object instances and serialized loadable object IDs for content directory builds.

Use this utility to populate a root asset or a LoadableObjectId field from a script. It is also useful when implementing custom Editor UI for ScriptableObjects or MonoBehaviours that contain Loadable<T0> or LoadableObjectId fields.

Additional resources: LoadableObjectId, Loadable<T0>, LoadableSceneIdEditorUtility

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}"); } } } }

Static Methods

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.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961