Search Unity

Alternative to ReplacePrefab

Discussion in 'Prefabs' started by Zullar, Jan 4, 2019.

  1. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    579
    Now that PrefabUtility.ReplacePrefab w/ ReplacePrefabOptions.ReplaceNameBased is obsolete I am unsure what to do.

    My workflow:
    1: I use a script to generate 100's of prefabs for monsters. I do this because my monsters hierarchies are complex and nearly identical. For example I may have an Orc, and a BigOrc that is 20% larger with slightly different stats.
    2: The prefab generating script makes a new prefab using PrefabUtility.CreatePrefab, and it modifies and brushes up on existing prefabs using PrefabUtility.ReplacePrefab w/ ReplacePrefabOptions.ReplaceNameBased.

    The reason PrefabUtility.ReplacePrefab w/ ReplacePrefabOptions.ReplaceNameBased is so important is it doesn't break any serialized scene links. Unfortunately the new PrefabUtility.SaveAsPrefabAsset breaks all scene.

    Here's an example of prefabs generated with a script. Again I use the script to make slightly modifications (tint one red and make it faster, or make one 30% larger and stronger, etc.)


    I am unsure what to do now that PrefabUtility.ReplacePrefab is obsolete. Thanks for any help.
     
    Last edited: Jan 5, 2019
    golmae likes this.
  2. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    579
    Edit: This will be fixed!

    https://forum.unity.com/threads/how...scripts-w-the-new-system.613747/#post-4113010

    From Unity
    "Hi,

    We’re working on a replacement for ReplacePrefab. You can keep using the obsolete API in the mean time. The replacement was meant to have been done when we shipped but didn't make it. It's a mistake on our part that the old method was marked obsolete without the replacement being ready. Sorry for the inconvenience."
     
    RandyLarson and golmae like this.