- Home /
Link to prefab breaks when recreating it
I have an editor extension that uses PrefabUtility.CreatePrefab() to create some prefabs. The problem is that I want to update a prefab without breaking links to that may exist in different scenes. Is this possible? I've tried using the different ReplacePrefabOptions but links seems to break no matter what I pick.
Hi, have you tried to modify the script to call PrefabUtility.ReplacePrefab when the prefab already exists ? There is some example on the documentation page (though, this example might not be exactly what you want as it uses CreateEmptyPrefab anyway)
PrefabUtility.ReplacePrefab didn't work either, I ended up with another solution that doesn't rely on creating/updating prefabs
Answer by ForceMagic · Mar 17, 2016 at 02:14 AM
I just encounter that same exact problem and using PrefabUtility.ReplacePrefab does work.
However, you have to pass the following:
Prefabutility.ReplacePrefab(goToCopy, prefabToReplace, ReplacePrefabOptions.ReplaceNameBased);
Otherwise, all the links will be broken, I've tried to use ConnectToPrefab at first, but wasn't working either.
At least if anyone else encounter this they will have their answers, I'm too late for you!