Search Unity

PrefabUtility.InstantiatePrefab not preserving prefab connection

Discussion in 'Scripting' started by murkantilism, Mar 7, 2017.

  1. murkantilism

    murkantilism

    Joined:
    Apr 30, 2012
    Posts:
    21
    This simple Editor tool to instantiate Prefabs is doing so, but the instantiated objects are missing their connection to the prefab (aka not blue, updating prefab doesn't show changes in copies).

    Code (CSharp):
    1. [ExecuteInEditMode]
    2.     public class FixMazePrefabConnections : MonoBehaviour
    3.     {
    4.         foreach (GameObject maze in mazes)
    5.         {
    6.             // Instantiate blank maze
    7.             GameObject newMaze = PrefabUtility.InstantiatePrefab(blankMazePrefab) as GameObject;
    8.         }
    9.     }
    I've tried suggestions like using:

    Code (CSharp):
    1. EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
    and:

    Code (CSharp):
    1. Undo.RecordObject(newMaze, "");
    to no avail. Any clue what I can try to preserve the connections?