Search Unity

PrefabUtility.SaveAsPrefabAsset() breaks references sometimes

Discussion in 'Prefabs' started by Kichang-Kim, Apr 18, 2019.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Hi, I found that PrefabUtility.SaveAsPrefabAsset() with existing prefab asset sometimes breaks references to it.

    Especially, it occured when version-control system is used.

    For example, user1 creates prefabs and commit it to repository, then user2 pull it and replace prefab with exatly same structure. But user2's pc, internal ID in replaced prefabs is changed somtimes, so references to it is broken. But when user2 revert broken prefab and re-open unity, replacing prefab doesn't make any changes!

    This issue is hard to make minumum repdroducible project, but makes me crazy. I used Unity 2018.3.12f1.

    If anyone has suffered with same issue, please share the experience or solution.
     
  2. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    When you say user2 replace the prefabs, what exactly is he doing?
     
  3. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Same action with user1. My project has AssetPostprocessor which geneates prefab from fbx in OnPostprocessAllAssets().

    So here is detail what happen:
    1. User 1 create/modify fbx A in his local Unity project.
    2. AssetPostprocessor automatically generates prefab A.
    3. User 1 commit fbx A and prefab A to repository.
    4. User 2 pull fbx A and prefab A.
    5. In user 2's local Unity project, prefab A is replaced by AssetPostprocessor.
    6. User2's prefab A is not same to pulled prefab A. (git says prefabA has changes)
    7. User2 close Unity then revert prefab A.
    8. User2 re-open Unity then manually re-import fbx A.
    9. AssetPostprocessor replaces User2's prefab A. <= No changes!
     
  4. vTimePawel

    vTimePawel

    Joined:
    Aug 1, 2017
    Posts:
    32
    Bump, I have the same issue, using SaveAsPrefabAsset breaks all references to the replaced prefab anywhere in the projects ("Missing"), using 2018.3.11f1.