x


ReplacePrefab() resets transforms for instanced prefabs?

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

more ▼

asked Mar 17 '11 at 01:51 PM

Rikard gravatar image

Rikard
11 1 1 2

Anyone? I'm really clueless about this.

Mar 30 '11 at 09:17 AM 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.

Jan 19 '12 at 02:10 AM nsxdavid

I'm having the same problem, it seems there's no way to do this. I was trying to make vertices to go back...

Oct 10 '12 at 09:49 AM watchoutfree
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Hi, try this: PrefabUtility.ReplacePrefab(go, thePrefab, ReplacePrefabOptions.ReplaceNameBased);

more ▼

answered Dec 18 '12 at 05:56 AM

TMPxyz gravatar image

TMPxyz
16 1 1 4

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1677
x1281
x1259
x168
x52

asked: Mar 17 '11 at 01:51 PM

Seen: 982 times

Last Updated: Dec 18 '12 at 05:56 AM