- Home /
The Script Equivilent of dragging a hierarchy of meshes over a preexisting prefab?
Hi Guys,
I'm having a hell of a time trying to update pre-existing prefabs during the OnPostprocessModel call. Using the EditorUtility.ReplacePrefab always overwrites the prefab completely.
List<GameObject> affectedPrefabs = mapAvailablePrefabs(gameObject);
if (assetPath.Contains("@") == false) {
string path = assetPath.Replace((gameObject.name +".FBX"),((returnRace(gameObject)) + gameObject.name + ".prefab"));
//Does .Prefab already exist at this path?
//This is mainly to insure that at least one prefab is created if base prefab does not exist.
if (!System.IO.File.Exists(path)){
Debug.Log("Creating Prefab: " + path);
Object prefab = PrefabUtility.CreateEmptyPrefab(path);
EditorUtility.ReplacePrefab(gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab);
}
foreach(GameObject prefabPath in affectedPrefabs)
{
//Updating PreFab
Debug.Log("Updating Prefab: " + prefabPath.name);
EditorUtility.ReplacePrefab(gameObject, prefabPath, ReplacePrefabOptions.ConnectToPrefab);
}
}
Thanks for you time! Nick
Okay, to clarify since im not getting any responses: I'm just try to update prexisting prefabs with new mesh data? I just don't understand why this is so difficult to answer.
Do I need to write a recursive method to collect the gameobjects components and completely rebuild it on update? It seems a little ridiculous. Why doesn't unity do this automatically anyway?
Cheers, Nick
Is it that you want to only replace a single part of an existing prefab? Or is the problem that the mesh data is not being copied over? What version of Unity are you using?
Im only trying to replace part of an existing prefab. 3.5.6 I think.
Thanks, Nick