Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


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

assetObject

The asset object to get the path of.

Returns

Type

Description

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

Examples

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.
Warning
Removed. Please use GetAssetPath(Object) with the asset reference (e.g. GetAssetPath(myObject) instead of GetAssetPath(myObject.GetInstanceID())), or GetAssetPath(EntityId) with the EntityId parameter type instead.
public static string GetAssetPath(int instanceID)

Parameters

instanceID

The instance ID of the asset.

Returns

Type

Description

stringThe 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

entityId

The EntityId of the asset.

Returns

Type

Description

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