GetDependencies
Gets the paths of all the assets that the asset at a path depends on, directly or indirectly.
Read time 3 minutesLast updated 3 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor.CoreModule
GetDependencies(string)
Gets the paths of all the assets that the asset at a path depends on, directly or indirectly.
public static string[] GetDependencies(string pathName)
Parameters
The project-relative path of the asset to get the dependencies of.
Returns
Type | Description |
|---|---|
| string[] | The project-relative paths of the dependencies, including the input path. |
Remarks
This method returns every asset that the input references, but not all of them are necessarily needed in a build. It returns only assets, not objects inside a file. For example, if a scene contains GameObjects that use a material, the method returns the path of the material but not the GameObjects. This overload includes indirect dependencies and the input path itself. To get only direct dependencies, use the overload that takes .
recursiveGetDependencies(string, bool)
Gets the paths of the assets that the asset at a path depends on, with the option to include indirect dependencies.
public static string[] GetDependencies(string pathName, bool recursive)
Parameters
Returns
Type | Description |
|---|---|
| string[] | The project-relative paths of the dependencies. |
Remarks
This method returns every asset that the input references, but not all of them are necessarily needed in a build. It returns only assets, not objects inside a file. For example, if a scene contains GameObjects that use a material, the method returns the path of the material but not the GameObjects.
GetDependencies(string[])
Gets the paths of all the assets that a list of assets depends on, directly or indirectly.
public static string[] GetDependencies(string[] pathNames)
Parameters
The project-relative paths of the assets to get the dependencies of.
Returns
Type | Description |
|---|---|
| string[] | The project-relative paths of the dependencies, including the input paths. |
Remarks
This method returns every asset that the input references, but not all of them are necessarily needed in a build. It returns only assets, not objects inside a file. For example, if a scene contains GameObjects that use a material, the method returns the path of the material but not the GameObjects. This overload includes indirect dependencies and the input paths themselves. To get only direct dependencies, use the overload that takes .
recursiveExamples
using System.Text;using UnityEditor;using UnityEngine;public class GetDependenciesExample : MonoBehaviour{ [MenuItem("APIExamples/GetDependencies")] static void GetAllDependenciesForScenes() { var allScenes = AssetDatabase.FindAssets("t:Scene"); string[] allPaths = new string[allScenes.Length]; int curSceneIndex = 0; foreach (var guid in allScenes) { var path = AssetDatabase.GUIDToAssetPath(guid); allPaths[curSceneIndex] = path; ++curSceneIndex; } var dependencies = AssetDatabase.GetDependencies(allPaths); StringBuilder dependenciesString = new StringBuilder(); dependenciesString.AppendLine(); foreach (var curDependency in dependencies) { dependenciesString.Append(curDependency); dependenciesString.AppendLine(); } Debug.Log("All dependencies for Scenes in Project: " + dependenciesString); }}
GetDependencies(string[], bool)
Gets the paths of the assets that a list of assets depends on, with the option to include indirect dependencies.
public static string[] GetDependencies(string[] pathNames, bool recursive)
Parameters
Returns
Type | Description |
|---|---|
| string[] | The project-relative paths of the dependencies. |
Remarks
This method returns every asset that the input references, but not all of them are necessarily needed in a build. It returns only assets, not objects inside a file. For example, if a scene contains GameObjects that use a material, the method returns the path of the material but not the GameObjects.