Access package assets using scripts
Use the prescribed path scheme to access or refer to assets within a package.
Read time 2 minutesLast updated 23 days ago
This section explains how to access or refer to assets that are defined inside a package:
Referring to package paths
To refer to assets that are defined inside a package, use this path scheme:
"Packages/<package-name>/..."
The path of the asset inside a package begins with and the package name (not the display name).
Packages/By contrast, you access project assets using this scheme:
"Assets/..."
For example, the path for the file in the package subfolder of the com.unity.images-library package is:
image.png/Example/Images"Packages/com.unity.images-library/Example/Images/image.png"
To get the absolute path of an item in your folder, you can use the partial path as a parameter to the Path.GetFullPath() method. For an example, refer to Resolving absolute paths.
PackagesLoading a Texture inside a package
To load a Texture stored inside a package, use the LoadAssetAtPath method, which requires the directive. Specify the path following the path scheme as demonstrated in this example:
using UnityEditorPackages/<package-name>/using UnityEditor;// ...Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath("Packages/com.unity.images-library/Example/Images/image.png", typeof(Texture2D));
Resolving absolute paths
To get the absolute path of a packaged asset, use the Path.GetFullPath() method, which requires the directive. For example:
using System.IOusing System.IO;// ...string absolute = Path.GetFullPath("Packages/com.unity.images-library/Example/Images/image.png");
Additional resources
- PackageInfo.name (Scripting API)
- Search for files