Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


AssetPathToGUID

Gets the GUID of the asset at a path, including assets deleted in the current Editor session.
Read time 2 minutesLast updated 3 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule

AssetPathToGUID(string)

Gets the GUID of the asset at a path, including assets deleted in the current Editor session.
public static string AssetPathToGUID(string path)

Parameters

path

The project-relative path of the asset.

Returns

Type

Description

stringThe 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. Paths are relative to the project folder, for example
Assets/MyTextures/hello.png
. For a version that returns a GUID, use AssetDatabase.GUIDFromAssetPath.

Examples

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.
public static string AssetPathToGUID(string path, AssetPathToGUIDOptions options)

Parameters

path

The project-relative path of the asset.

Whether to return GUIDs for assets deleted in the current Editor session. The default value is AssetPathToGUIDOptions.IncludeRecentlyDeletedAssets.

Returns

Type

Description

stringThe 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 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.