| Parameter | Description |
|---|---|
| instanceID | The instance ID of the object. |
| obj | The object to get the GUID and local file identifier for. |
| guid | When the method returns, contains the GUID of the asset file. |
| localId | When the method returns, contains the local file identifier of the object. |
bool True if the method found the GUID and local file identifier. Otherwise, false.
Gets the GUID and local file identifier of an object, using obsolete parameter types.
These overloads are obsolete. Local file identifiers can be longer than 32 bits, for example for prefabs, so use an overload that takes a long for localId and an EntityId or Object for the object.
| Parameter | Description |
|---|---|
| obj | The object to get the GUID and local file identifier for. |
| guid | When the method returns, contains the GUID of the asset file. |
| localId | When the method returns, contains the local file identifier of the object. |
bool True if the method found the GUID and local file identifier. Otherwise, false.
Gets the GUID and local file identifier of an object.
When Unity serializes a reference to an asset, it stores the GUID of the asset file and a file ID that identifies the object inside the file. If a project uses text serialization, you can edit this information by hand. For more information, refer to Editor Settings. A common use is moving C# scripts from a project into a DLL, while keeping the GameObjects that use those scripts intact. For example, a project contains a MonoBehaviour script, a scene, and a GameObject with the script attached. The serialized scene file contains something like this, reduced to the relevant parts:
/* example .unity Scene contents:
--- !u!1 &65078845 GameObject: m_Component: -component: {fileID : 65078850} --- !u!114 &65078850 MonoBehaviour: m_Script: {fileID : 11500000, guid : 9cbd8cdf99d44b58972fbc7f6f38088f, type : 3}
*/
using System.Text; using UnityEngine; using UnityEditor;
class ShowAssetIds { [MenuItem("Assets/Show Asset Ids")] static void MenuShowIds() { var stringBuilder = new StringBuilder();
foreach (var obj in AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(Selection.activeObject))) { string guid; long file;
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out guid, out file)) { stringBuilder.AppendFormat("Asset: " + obj.name + "\n EntityId: " + obj.GetEntityId() + "\n GUID: " + guid + "\n File ID: " + file); } }
Debug.Log(stringBuilder.ToString()); } }
Additional resources: GlobalObjectId.
| Parameter | Description |
|---|---|
| entityId | The EntityId of the object. |
| guid | When the method returns, contains the GUID of the asset file. |
| localId | When the method returns, contains the local file identifier of the object. |
bool True if the method found the GUID and local file identifier. Otherwise, false.
Gets the GUID and local file identifier of the object with the specified EntityId.
When Unity serializes a reference to an asset, it stores the GUID of the asset file and a file ID that identifies the object inside the file. Use this method to get both values for an object. For a full explanation and example, refer to AssetDatabase.TryGetGUIDAndLocalFileIdentifier.
| Parameter | Description |
|---|---|
| assetRef | The lazy-load reference to the asset. |
| guid | When the method returns, contains the GUID of the asset file. |
| localId | When the method returns, contains the local file identifier of the object. |
bool True if the method found the GUID and local file identifier. Otherwise, false.
Gets the GUID and local file identifier of the asset that a lazy-load reference points to.
Use this overload to get the GUID and local file identifier without loading the referenced asset. For a full explanation, refer to AssetDatabase.TryGetGUIDAndLocalFileIdentifier.