- Home /
Question by
murkantilism · Mar 07, 2017 at 07:00 PM ·
instantiateeditor-scriptingeditorscriptprefabutilityprefab connection
PrefabUtility.InstantiatePrefab not preserving prefab connection
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).
[ExecuteInEditMode]
public class FixMazePrefabConnections : MonoBehaviour
{
foreach (GameObject maze in mazes)
{
// Instantiate blank maze
GameObject newMaze = PrefabUtility.InstantiatePrefab(blankMazePrefab) as GameObject;
}
}
I've tried suggestions like using:
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
and:
Undo.RecordObject(newMaze, "");
to no avail. Any clue what I can try to preserve the connections?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612112649im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Editor Script: Linking GameObjects to public script variables resets when playing. 1 Answer
Saving a variable from an editor script into something like a gamemanager script? 0 Answers
Create varying numbers of gameObjects/prefabs in sceneview? 0 Answers
How to create instance from model without creating a clone? 2 Answers
How do I change the name of the prefab in the prefab folder with code? 0 Answers