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

AssetDatabase.GetAssetPath

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 GetAssetPath(EntityId entityId);

Parameters

Parameter Description
entityId The EntityId of the asset.

Returns

string The project-relative path of the asset, or an empty string if the asset doesn't exist.

Description

Gets the path of the asset with the specified EntityId, relative to the project folder.

Use this method to find where an asset is stored. Paths are relative to the project folder, for example Assets/MyTextures/hello.png.


Declaration

public static string GetAssetPath(Object assetObject);

Parameters

Parameter Description
assetObject The asset object to get the path of.

Returns

string The project-relative path of the asset, or an empty string if the asset doesn't exist.

Description

Gets the path of an asset object, relative to the project folder.

Use this method to find where an asset is stored. Paths are relative to the project folder, for example Assets/MyTextures/hello.png.

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

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

Declaration

public static string GetAssetPath(int instanceID);

Parameters

Parameter Description
instanceID The instance ID of the asset.

Returns

string The project-relative path of the asset, or an empty string if the asset doesn't exist.

Description

Gets the path of the asset with the specified instance ID, relative to the project folder.

This overload is obsolete. Use the overload that takes an EntityId instead.