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

AssetDatabase.AssetPathToGUID

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

Declaration

public static string AssetPathToGUID(string path);

Parameters

Parameter Description
path The project-relative path of the asset.

Returns

string The GUID of the asset as a string, or an empty string if no GUID exists for the path.

Description

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

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.

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 } }

Declaration

public static string AssetPathToGUID(string path, AssetPathToGUIDOptions options = AssetPathToGUIDOptions.IncludeRecentlyDeletedAssets);

Parameters

Parameter Description
path The project-relative path of the asset.
options Whether to return GUIDs for assets deleted in the current Editor session. The default value is AssetPathToGUIDOptions.IncludeRecentlyDeletedAssets.

Returns

string The GUID of the asset as a string, or an empty string if no GUID exists for the path.

Description

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

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.