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

AssetDatabase.GetDependencies

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[] GetDependencies(string pathName);

Parameters

Parameter Description
pathName The project-relative path of the asset to get the dependencies of.

Returns

string[] The project-relative paths of the dependencies, including the input path.

Description

Gets the paths of all the assets that the asset at a path depends on, directly or indirectly.

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


Declaration

public static string[] GetDependencies(string pathName, bool recursive);

Parameters

Parameter Description
pathName The project-relative path of the asset to get the dependencies of.
recursive Set to true to include indirect dependencies and the input paths themselves. Set to false to include only direct dependencies.

Returns

string[] The project-relative paths of the dependencies.

Description

Gets the paths of the assets that the asset at a path depends on, with the option to include indirect dependencies.

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.


Declaration

public static string[] GetDependencies(string[] pathNames);

Parameters

Parameter Description
pathNames The project-relative paths of the assets to get the dependencies of.

Returns

string[] The project-relative paths of the dependencies, including the input paths.

Description

Gets the paths of all the assets that a list of assets depends on, directly or indirectly.

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

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

Declaration

public static string[] GetDependencies(string[] pathNames, bool recursive);

Parameters

Parameter Description
pathNames The project-relative paths of the assets to get the dependencies of.
recursive Set to true to include indirect dependencies and the input paths themselves. Set to false to include only direct dependencies.

Returns

string[] The project-relative paths of the dependencies.

Description

Gets the paths of the assets that a list of assets depends on, with the option to include indirect dependencies.

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.