# TryGetGUIDAndLocalFileIdentifier

> Gets the GUID and local file identifier of an object.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/7000.0/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

## TryGetGUIDAndLocalFileIdentifier(Object, string, long)

Gets the GUID and local file identifier of an object.

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

### Parameters

**** (\[Object]\(/engine/7000.0/script-reference/unityengine/object)): The object to get the GUID and local file identifier for.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): When the method returns, contains the GUID of the asset file.**** (\[long]\(https\://learn.microsoft.com/dotnet/api/system.int64)): When the method returns, contains the local file identifier of the object.

### Returns

| Type                                                          | Description                                                                    |
| ------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the method found the GUID and local file identifier. Otherwise, false. |

### Remarks

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](/engine/7000.0/manual/unity-editor/editor-settings-reference/comp-manager-group/class-editor-manager.md). 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:

```csharp
/* 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}

*/
```

```csharp
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](/engine/7000.0/script-reference/unityeditor/globalobjectid.md).

## TryGetGUIDAndLocalFileIdentifier(int, string, long)

Gets the GUID and local file identifier of an object, using obsolete parameter types.

> **Warning:**
>
> **Removed.** Please use TryGetGUIDAndLocalFileIdentifier(EntityId, out string, out long) with the EntityId type instead.

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

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The instance ID of the object.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): When the method returns, contains the GUID of the asset file.**** (\[long]\(https\://learn.microsoft.com/dotnet/api/system.int64)): When the method returns, contains the local file identifier of the object.

### Returns

| Type                                                          | Description                                                                    |
| ------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the method found the GUID and local file identifier. Otherwise, false. |

### Remarks

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](/engine/7000.0/script-reference/unityengine/entityid.md) or [Object](/engine/7000.0/script-reference/unityengine/object.md) for the object.

## TryGetGUIDAndLocalFileIdentifier(EntityId, string, long)

Gets the GUID and local file identifier of the object with the specified EntityId.

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

### Parameters

**** (\[EntityId]\(/engine/7000.0/script-reference/unityengine/entityid)): The EntityId of the object.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): When the method returns, contains the GUID of the asset file.**** (\[long]\(https\://learn.microsoft.com/dotnet/api/system.int64)): When the method returns, contains the local file identifier of the object.

### Returns

| Type                                                          | Description                                                                    |
| ------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the method found the GUID and local file identifier. Otherwise, false. |

### Remarks

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](/engine/7000.0/script-reference/unityeditor/assetdatabase/trygetguidandlocalfileidentifier.md).

## TryGetGUIDAndLocalFileIdentifier\<T>(LazyLoadReference\<T>, string, long)

Gets the GUID and local file identifier of the asset that a lazy-load reference points to.

```csharp
public static bool TryGetGUIDAndLocalFileIdentifier<T>(LazyLoadReference<T> assetRef, out string guid, out long localId) where T : Object
```

### Parameters

**** (\[LazyLoadReference\<T>]\(/engine/7000.0/script-reference/unityengine/lazyloadreference1)): The lazy-load reference to the asset.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): When the method returns, contains the GUID of the asset file.**** (\[long]\(https\://learn.microsoft.com/dotnet/api/system.int64)): When the method returns, contains the local file identifier of the object.

### Returns

| Type                                                          | Description                                                                    |
| ------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if the method found the GUID and local file identifier. Otherwise, false. |

### Remarks

Use this overload to get the GUID and local file identifier without loading the referenced asset. For a full explanation, refer to [AssetDatabase.TryGetGUIDAndLocalFileIdentifier](/engine/7000.0/script-reference/unityeditor/assetdatabase/trygetguidandlocalfileidentifier.md).
