Version: Unity 7.0 Alpha (7000.0)
LanguageEnglish
  • C#

AssetDatabase.TryGetGUIDAndLocalFileIdentifier

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

Obsolete Please use TryGetGUIDAndLocalFileIdentifier(EntityId, out string, out long) with the EntityId type instead.

Declaration

public static bool TryGetGUIDAndLocalFileIdentifier(int instanceID, out string guid, out long localId);

Parameters

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.

Returns

bool True if the method found the GUID and local file identifier. Otherwise, false.

Description

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.


Declaration

public static bool TryGetGUIDAndLocalFileIdentifier(Object obj, out string guid, out long localId);

Parameters

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.

Returns

bool True if the method found the GUID and local file identifier. Otherwise, false.

Description

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.


Declaration

public static bool TryGetGUIDAndLocalFileIdentifier(EntityId entityId, out string guid, out long localId);

Parameters

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.

Returns

bool True if the method found the GUID and local file identifier. Otherwise, false.

Description

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.


Declaration

public static bool TryGetGUIDAndLocalFileIdentifier(LazyLoadReference<T> assetRef, out string guid, out long localId);

Parameters

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.

Returns

bool True if the method found the GUID and local file identifier. Otherwise, false.

Description

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.