Search Unity

Question How to use the 'GlobalArtifactDependencyVersion'?

Discussion in 'Asset Database' started by watsonsong, Sep 5, 2022.

  1. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I have some heavy custom asset collection base on search, filter and asset dependency. I want to cache the result and reuse them again and again if the asset database is not changed. For example maybe I want to cache all asset dependency and show in different editor GUI.
    I think I can avoid recalcualte the use the new 'GlobalArtifactXXXVersion' to invalide the cache in memory. What the different about the 'GlobalArtifactDependencyVersion' and 'GlobalArtifactProcessedVersion'? How can I resuse them correctly?

    I did't see much examples or articles to explain them. And I can not find any usage case from the document.
     
  2. TobiasThomsen

    TobiasThomsen

    Unity Technologies

    Joined:
    Feb 15, 2021
    Posts:
    20
    Hi watsonsong,
    If you need a way to see whether a change has been done to any dependency, use GlobalArtifactDependencyVersion. This API will let you know if ANY dependency information (something that another asset might depend on) has changed, even if no asset is depending on this.
    GlobalArtifactProcessedVersion is for detecting if a new import result has been added to the artifact database, meaning if an asset has been re-imported because of an invalidated version in the artifact database.
    I hope that helps you out :).
     
  3. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Thanks for your replay.
    So the GlobalArtifactProcessedVersion means the artifact content MAYBE changed, if the source asset changed, AssetPostProcessor version changed, or just manual reimport a source asset?
    The GlobalArtifactProcessedVersion change dose not mean the artifact is changed. And the artifact changed does not mean the GlobalArtifactDependencyVersion will change because the artifact maybe not modify any dependency.

    So if I implement a AssetDependencyTracker, I can first check the GlobalArtifactDependencyVersion to invalidate the whole dependency graph cache just IN MEMORY. If the version changed, I can again use the GetAssetDependencyHash to cache the GetDependencies results IN DISK.

    I don't know whether am I correct?