Hi, I have a problem with instanced objects getting their transforms reseted back to their initial Prefab transform values. All this happens when I re-import a model that is processed through a editor script in OnPostprocessModel(). In this script I apply BoxColliders, scripts and so on. Everything works great except for the transform-problem. Here's the code snippet I think is causing the problem.
//Instantiate the loaded model in the scene temporarily to make changes to
var go:GameObject = GameObject.Instantiate(model, Vector3.zero, Quaternion.identity) as GameObject;
//Search for prefab at path
var prefabName:String = "Assets/Prefabs/LevelComponents/GroundComponents/" + model.name + ".prefab";
var prefab:Object = AssetDatabase.LoadAssetAtPath(prefabName, Object) as Object;
if(prefab == null)
{
Debug.Log("Couldn't find any prefab with the name: " + model.name);
Debug.Log("Creating prefab: " + model.name);
prefab = EditorUtility.CreateEmptyPrefab(prefabName);
}
else
{
Debug.Log("Found prefab to update. Updating: " + model.name);
}
//Replace prefab with the modified GameObject
EditorUtility.ReplacePrefab(go, prefab);
//Remove the GameObject from scene
Editor.DestroyImmediate(go, true);
So my question is if there's a way to update a prefab with "reimport" and process the model without reseting the transforms for the instanced objects in scenes? Thanks, /Rikard
We are seeing this same problem. Worse... the object then has some sort of psychic connection to the prefab. Changing the prefab's transform immediately modifies the instances in the scene. That just ain't right.
– nsxdavidI'm having the same problem, it seems there's no way to do this. I was trying to make vertices to go back...
– watchoutfree