# GetDependencies

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

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/7000.0/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

## GetDependencies(string)

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

```csharp
public static string[] GetDependencies(string pathName)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The project-relative path of the asset to get the dependencies of.

### Returns

| Type                                                               | Description                                                               |
| ------------------------------------------------------------------ | ------------------------------------------------------------------------- |
| [string\[\]](https://learn.microsoft.com/dotnet/api/system.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 `recursive`.

## GetDependencies(string, bool)

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

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

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The project-relative path of the asset to get the dependencies of.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Set to true to include indirect dependencies and the input paths themselves. Set to false to include only direct dependencies.

### Returns

| Type                                                               | Description                                     |
| ------------------------------------------------------------------ | ----------------------------------------------- |
| [string\[\]](https://learn.microsoft.com/dotnet/api/system.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.

```csharp
public static string[] GetDependencies(string[] pathNames)
```

### Parameters

**** (\[string\[]]\(https\://learn.microsoft.com/dotnet/api/system.string)): The project-relative paths of the assets to get the dependencies of.

### Returns

| Type                                                               | Description                                                                |
| ------------------------------------------------------------------ | -------------------------------------------------------------------------- |
| [string\[\]](https://learn.microsoft.com/dotnet/api/system.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 `recursive`.

### Examples

```csharp
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.

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

### Parameters

**** (\[string\[]]\(https\://learn.microsoft.com/dotnet/api/system.string)): The project-relative paths of the assets to get the dependencies of.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Set to true to include indirect dependencies and the input paths themselves. Set to false to include only direct dependencies.

### Returns

| Type                                                               | Description                                     |
| ------------------------------------------------------------------ | ----------------------------------------------- |
| [string\[\]](https://learn.microsoft.com/dotnet/api/system.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.
