# AssetPathToGUID

> Gets the GUID of the asset at a path, including assets deleted in the current Editor session.

## Definition

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

## AssetPathToGUID(string)

Gets the GUID of the asset at a path, including assets deleted in the current Editor session.

```csharp
public static string AssetPathToGUID(string path)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The project-relative path of the asset.

### Returns

| Type                                                           | Description                                                                           |
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The GUID of the asset as a string, or an empty string if no GUID exists for the path. |

### Remarks

When you delete an asset, its GUID stays in the Asset Database until you close the Unity Editor, so this overload still returns GUIDs for assets that you deleted in the current Editor session. For assets that don't exist and weren't deleted in the current session, it returns an empty string. To get an empty string for deleted assets too, use the overload that takes [AssetPathToGUIDOptions](/engine/7000.0/script-reference/unityeditor/assetpathtoguidoptions.md). Paths are relative to the project folder, for example `Assets/MyTextures/hello.png`. For a version that returns a GUID, use [AssetDatabase.GUIDFromAssetPath](/engine/7000.0/script-reference/unityeditor/assetdatabase/guidfromassetpath.md).

### Examples

```csharp
using UnityEngine;
using UnityEditor;

public class Example : MonoBehaviour
{
    [MenuItem("AssetDatabase/AssetPathToGUID")]
    static void Doit()
    {
        // texture.jpg exists or was recently deleted
        string t = AssetDatabase.AssetPathToGUID("Assets/texture.jpg");
        Debug.Log(t); // t will be not null
    }

    [MenuItem("AssetDatabase/AssetPathToGUID Existing Assets Only")]
    static void DoitExistingAssetsOnly()
    {
        // texture.jpg does not exist on disk
        string t = AssetDatabase.AssetPathToGUID("Assets/texture.jpg", AssetPathToGUIDOptions.OnlyExistingAssets);
        Debug.Log(t); // t will be null
    }
}
```

## AssetPathToGUID(string, AssetPathToGUIDOptions)

Gets the GUID of the asset at a path, with the option to exclude assets deleted in the current Editor session.

```csharp
public static string AssetPathToGUID(string path, AssetPathToGUIDOptions options)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The project-relative path of the asset.**** (\[AssetPathToGUIDOptions]\(/engine/7000.0/script-reference/unityeditor/assetpathtoguidoptions)): Whether to return GUIDs for assets deleted in the current Editor session. The default value is [AssetPathToGUIDOptions.IncludeRecentlyDeletedAssets](/engine/7000.0/script-reference/unityeditor/assetpathtoguidoptions/includerecentlydeletedassets.md).

### Returns

| Type                                                           | Description                                                                           |
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | The GUID of the asset as a string, or an empty string if no GUID exists for the path. |

### Remarks

By default, the GUID of a deleted asset stays in the Asset Database until you close the Unity Editor. Pass [AssetPathToGUIDOptions.OnlyExistingAssets](/engine/7000.0/script-reference/unityeditor/assetpathtoguidoptions/onlyexistingassets.md) to get an empty string for assets that you deleted in the current Editor session. For assets that don't exist and weren't deleted in the current session, the method returns an empty string. Paths are relative to the project folder, for example `Assets/MyTextures/hello.png`. For a version that returns a GUID, use [AssetDatabase.GUIDFromAssetPath](/engine/7000.0/script-reference/unityeditor/assetdatabase/guidfromassetpath.md).
