Search Unity

Storing reference to another prefab not working

Discussion in 'Prefabs' started by schinkowski, Feb 21, 2019.

  1. schinkowski

    schinkowski

    Joined:
    Jun 11, 2016
    Posts:
    2
    I am using PrefabUtility.SaveAsPrefabAsset to save a prefab from an AssetPostprocessor. I have another prefab that has an array of GameObjects that reference the other prefabs saved with PrefabUtility.SaveAsPrefabAsset. However, when I look at the saved prefab, all those references say "Missing (Game Object)".

    This is the code I'm using:
    Code (CSharp):
    1. GameObject A;
    2. string pathA;
    3.  
    4. // ... parse files to generate GameObject A
    5.  
    6. GameObject savedPefabA = PrefabUtility.SaveAsPrefabAsset(A, pathA);
    7.  
    8. AssetDatabase.SaveAssets();
    9.  
    10. GameObject B;
    11. string pathB;
    12.  
    13. // Assign references of savedPefabA to GameObject B's component
    14.  
    15. PrefabUtility.SaveAsPrefabAsset(B, pathB);
    This used to work in Unity 2018 with PrefabUtility.ReplacePrefab() but that method is now obsolete.
    If I link the prefabs in editor manually it works but I need to automate this in the AssetPostprocessor. What am I doing wrong?
     
  2. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @schinkowski

    I don't see why this would not work, could you please file a bug report with a small project and steps to reproduce.
     
  3. schinkowski

    schinkowski

    Joined:
    Jun 11, 2016
    Posts:
    2
    Thanks for your reply. I was able to create a small project that reproduces the issue and filed a bug report.