Search Unity

Bug AssetDatabase.GetDependencies returns references to assets from deleted members

Discussion in 'Asset Database' started by rskorski-wizards, Aug 9, 2020.

  1. rskorski-wizards

    rskorski-wizards

    Joined:
    Feb 27, 2018
    Posts:
    8
    We've found some behavior with AssetDatabase.GetDependencies and prefab variants that seems like a bug.

    We've got a prefab with a behavior that has a member referencing another asset. There is a variant of that prefab which overrides that member to reference a different asset. If that member is deleted, then a call to AssetDatabase.GetDependencies will continue to return old referenced asset for the variant, but not the base.

    The variant's file will still refer to the old asset, which is great so the value comes back if we bring back that member. But since an instance won't actually need that asset, it seems like a bug that it's listed as a dependency. We use AssetDatabase.GetDependencies in our system that builds our asset bundles to group asset dependency chains into the same bundle. Since we're getting stale data, our bundles are including assets that they shouldn't.

    We've entered a bug on that: https://fogbugz.unity3d.com/default.asp?1269085_3d558eqgqhfcmc4c

    I'll also note that before deleting the member, AssetDatabase.GetDependencies would return the asset that the base referenced as well as the asset it referenced with its override. This is understandable: Variant depends on Base, which depends on base's references asset. But it seems like it would be Most Correct(TM) if the prefab variant's reference overrides hid the parent's references, because I don't think you can reach them in any way from code or in the hierarchy if you only have an instance of the variant.
     
    Last edited: Aug 10, 2020
    WotC_DavidB likes this.
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Seems like an instance of the issue mentioned in this thread.

    @SteenLund, did any kind of workaround or fix happen since that thread?
     
  3. rskorski-wizards

    rskorski-wizards

    Joined:
    Feb 27, 2018
    Posts:
    8
    Our bug report got linked to a public issue!

    https://issuetracker.unity3d.com/is...efab-file-when-the-reference-field-is-deleted

    I think this issue is written up in a way that's too implementation focused, and I hope that doesn't put it in a bad light. The bug, imo, is that GetDependencies returns assets that are not referenced by instantiated assets, not the fact that the data exists in the file. In the thread @Baste linked, the Unity devs seem to understand that, I'm just echoing that sentiment here.

    The tool @steinbitglis references (http://wiki.unity3d.com/index.php/P...464.521043808.1597007070-156582472.1570556149) is neat! In our situation it didn't work out of the box because the prefabs are not referenced directly from a scene. We have some indirection it wouldn't follow with layers of TextAssets in the way, but it takes care of most of the work needed. We may use that as a starting point if the problem becomes big for us.