GetAssetPath
Gets the path of an asset object, relative to the project folder.
Read time 2 minutesLast updated 3 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor.CoreModule
GetAssetPath(Object)
Gets the path of an asset object, relative to the project folder.
public static string GetAssetPath(Object assetObject)
Parameters
The asset object to get the path of.
Returns
Type | Description |
|---|---|
| string | The project-relative path of the asset, or an empty string if the asset doesn't exist. |
Remarks
Use this method to find where an asset is stored. Paths are relative to the project folder, for example .
Assets/MyTextures/hello.pngExamples
using UnityEngine;using UnityEditor;public class CreateMaterialExample : MonoBehaviour{ [MenuItem("GameObject/Create Material")] static void CreateMaterial() { // Create a simple material asset Material material = new Material(Shader.Find("Specular")); AssetDatabase.CreateAsset(material, "Assets/MyMaterial.mat"); // Print the path of the created asset Debug.Log(AssetDatabase.GetAssetPath(material)); }}
GetAssetPath(int)
Gets the path of the asset with the specified instance ID, relative to the project folder.
public static string GetAssetPath(int instanceID)
Parameters
The instance ID of the asset.
Returns
Type | Description |
|---|---|
| string | The project-relative path of the asset, or an empty string if the asset doesn't exist. |
Remarks
This overload is obsolete. Use the overload that takes an EntityId instead.
GetAssetPath(EntityId)
Gets the path of the asset with the specified EntityId, relative to the project folder.
public static string GetAssetPath(EntityId entityId)
Parameters
The EntityId of the asset.
Returns
Type | Description |
|---|---|
| string | The project-relative path of the asset, or an empty string if the asset doesn't exist. |
Remarks
Use this method to find where an asset is stored. Paths are relative to the project folder, for example .
Assets/MyTextures/hello.png