I am seeing differences between what I get from AssetDatabase.GetDependencies() and the list of files that an interactive ExportPackage() offers me when invoking both on the same asset and I am not sure why.
This is not about .cs files which I now ExportPackage() is quite conservative about, but regular assets dependencies.
More details:
All of my model files (FBX) come with a sibling custom descriptor file that I am using to reference e.g. various textures that I can apply at runtime to this model.
So the dependency graph looks like this: Model -> descriptor file -> textures etc.
I have a model AssetPostprocessor that correctly set up the dependency from the model to the descriptor file, and my custom descriptor file importer correctly set up the dependencies to the textures.
And it seems to be working fine with the regular package export that indeed offers me to export the following items:
- descriptorFile
- texture0
- texture1
etc.```
However calling AssetDatabase.GetDependencies() on the same model asset will only yield
```- Model.fbx
- A lit shader (I suppose the default one listed by the FBX)```
So, my two questions:
- what is causing this discrepancy?
- how can I retrieve the actual dependencies as show by ExportPackage?
Thanks!
Hi @g4ma ,
Looking through the source of both Export and AssetDatabase.GetDependencies, I can see that Export uses AssetDatabase.GetDependencies (under the hood).
The only potential difference could be the recursive parameter inside of AssetDatabase.GetDependencies as that will go through the dependency chain and get the guids of an assetsâ dependencies.
This âinclude dependenciesâ value gets used internally by GetDependencies:
Investigating a bit more, the only workaround I could find was this: relying on an AssetPostProcessor, in a OnPostprocessModel() I added a custom MonoBehaviour on the GameObject and made sure to have it reference my descriptor file as a property field :
Thatâs interesting, that it almost depends when during import you setup the dependency.
We have this API: AssetImportContext.DependsOnSourceAsset
AssetPostprocessorâs have an AssetImportContext field (context) available (though I believe it may not be widely known, or obvious tbh).
Could you please try doing this inside either the postprocessor, or in your actual code, if youâre not doing so already:
Note that AssetDatabase.GetDependencies returns assets being referenced (a runtime dependency) whereas calling context.DependsOnSourceAsset(guid); will setup an import-time dependency. Difference between these two kinds of dependencies are:
Import time dependency: Registered in the asset database to decide if an asset should be reimported because a dependency has changed.
Runtime dependency: Anything the asset needs to be available at runtime for it to work property. E.g. assets that are referenced through a member field.
Thatâs interesting, thanks for this! It looks like some dependencies were indeed incorrectly setup.
However I donât really get how ExportPackage() could only be based on GetDependencies() if the latter only returns runtime dependencies.
To me exporting an asset as a package would require pulling its import time dependencies - if it did not, the exported asset would not be viable once reimported in e.g. another project. And indeed the behaviour I see with ExportPackage() shows that all import time dependencies are correctly listed.
So getting back to the original question: given an asset how can I get its import time dependencies rather than only its runtime dependencies? Is there an API for this?
Correct⌠ExportPackage() uses GetDependencies() and also collects import time dependencies. Unfortunately the import time dependencies are only exposed as internal and not public API. We should probably change that. But as a work around until then you can use c# reflection to call the internal functions. The functions are
Thatâs perfect, thanks!
I should have had a look at the AssetDatabase bindings, I would probably have seen those.
Is there a formal process to get these exposed? My use case (getting import time dependencies) is pretty common in the context of assets pipeline development.