# GetDependencies

> Returns an array of all the assets that are dependencies of the asset at the specified pathName. Note: AssetDatabase.GetDependencies () gets the Assets that are referenced by other Assets. For example, a Scene could contain many GameObjects with a Material attached to them. In this case, AssetDatabase.GetDependencies () will return the path to the Material Assets, but not the GameObjects as those are not Assets on your disk.

## Definition

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

## GetDependencies(string)

Returns an array of all the assets that are dependencies of the asset at the specified **pathName**.

**Note:** [AssetDatabase.GetDependencies](/engine/6000.7/script-reference/unityeditor/assetdatabase/getdependencies.md)() gets the Assets that are referenced by other Assets. For example, a Scene could contain many GameObjects with a Material attached to them. In this case,  [AssetDatabase.GetDependencies](/engine/6000.7/script-reference/unityeditor/assetdatabase/getdependencies.md)() will return the path to the Material Assets, but not the GameObjects as those are not Assets on your disk.

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

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The path to the asset for which dependencies are required.

### Returns

| Type                                                               | Description                                        |
| ------------------------------------------------------------------ | -------------------------------------------------- |
| [string\[\]](https://learn.microsoft.com/dotnet/api/system.string) | The paths of all assets that the input depends on. |

### Remarks

If **recursive** is true, the list returned will also include the input path itself.  Note that this function returns all assets that are referenced by the input asset; these references are not necessarily required during the build process.

## GetDependencies(string, bool)

Returns an array of all the assets that are dependencies of the asset at the specified **pathName**.

**Note:** [AssetDatabase.GetDependencies](/engine/6000.7/script-reference/unityeditor/assetdatabase/getdependencies.md)() gets the Assets that are referenced by other Assets. For example, a Scene could contain many GameObjects with a Material attached to them. In this case,  [AssetDatabase.GetDependencies](/engine/6000.7/script-reference/unityeditor/assetdatabase/getdependencies.md)() will return the path to the Material Assets, but not the GameObjects as those are not Assets on your disk.

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

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The path to the asset for which dependencies are required.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Controls whether this method recursively checks and returns all dependencies including indirect dependencies (when set to true), or whether it only returns direct dependencies (when set to false).

### Returns

| Type                                                               | Description                                        |
| ------------------------------------------------------------------ | -------------------------------------------------- |
| [string\[\]](https://learn.microsoft.com/dotnet/api/system.string) | The paths of all assets that the input depends on. |

### Remarks

If **recursive** is true, the list returned will also include the input path itself.  Note that this function returns all assets that are referenced by the input asset; these references are not necessarily required during the build process.

## GetDependencies(string\[])

Returns an array of the paths of assets that are dependencies of all the assets in the list of **pathName**s that you provide.

**Note:** [AssetDatabase.GetDependencies](/engine/6000.7/script-reference/unityeditor/assetdatabase/getdependencies.md)() gets the Assets that are referenced by other Assets. For example, a Scene could contain many GameObjects with a Material attached to them. In this case,  [AssetDatabase.GetDependencies](/engine/6000.7/script-reference/unityeditor/assetdatabase/getdependencies.md)() will return the path to the Material Assets, but not the GameObjects as those are not Assets on your disk.

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

### Parameters

**** (\[string\[]]\(https\://learn.microsoft.com/dotnet/api/system.string)): The path to the assets for which dependencies are required.

### Returns

| Type                                                               | Description                                        |
| ------------------------------------------------------------------ | -------------------------------------------------- |
| [string\[\]](https://learn.microsoft.com/dotnet/api/system.string) | The paths of all assets that the input depends on. |

### Remarks

If **recursive** is true, the list returned will also include the input paths themselves.  Note that this function returns all assets that are referenced by the input asset; these references are not necessarily required during the build process.

### 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)

Returns an array of the paths of assets that are dependencies of all the assets in the list of **pathName**s that you provide.

**Note:** [AssetDatabase.GetDependencies](/engine/6000.7/script-reference/unityeditor/assetdatabase/getdependencies.md)() gets the Assets that are referenced by other Assets. For example, a Scene could contain many GameObjects with a Material attached to them. In this case,  [AssetDatabase.GetDependencies](/engine/6000.7/script-reference/unityeditor/assetdatabase/getdependencies.md)() will return the path to the Material Assets, but not the GameObjects as those are not Assets on your disk.

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

### Parameters

**** (\[string\[]]\(https\://learn.microsoft.com/dotnet/api/system.string)): The path to the assets for which dependencies are required.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Controls whether this method recursively checks and returns all dependencies including indirect dependencies (when set to true), or whether it only returns direct dependencies (when set to false).

### Returns

| Type                                                               | Description                                        |
| ------------------------------------------------------------------ | -------------------------------------------------- |
| [string\[\]](https://learn.microsoft.com/dotnet/api/system.string) | The paths of all assets that the input depends on. |

### Remarks

If **recursive** is true, the list returned will also include the input paths themselves.  Note that this function returns all assets that are referenced by the input asset; these references are not necessarily required during the build process.

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