Getting direct dependencies for an asset

I’d like how can i retrieve an asset’s direct dependencies (non-transitive).

The AssetDatabase.GetDependencies method will return transitive dependencies.

By transitive, i mean:

  • Prefab A references Prefab B (e.g: has a script with a GameObject field that gets set to Prefab B).
  • Prefab B references an AudioClip

When requesting the dependencies of Prefab A, the AudioClip is also returned (even though it is not a direct dependency).

I want an API (or some other way) to find out the direct dependencies of an asset.

Unity doesn’t allow prefabs to use other prefabs. Your best bet is to do treat prefab B as a resource and load it through prefab A when you need it.
Or if not as a resource, have a script in prefab a reference and Instantiate prefab b.