Is there a way to edit an instantiated prefab without modifying the prefab itself?

Hey Everybody,
I am instantiating a prefab using an editor script. Then, I am modifying the instantiated object (say, adding a rigidbody to it). This should work, but it’s actually modifying the prefab, rather than the instantiation of it. Am I missing something obvious here? Please help out. Here is a sample of the code:

UnityEngine.Object prefabObject = AssetDatabase.LoadAssetAtPath(newObjectFullPath, typeof(GameObject));
GameObject newObject = Instantiate(prefabObject) as GameObject;

So, am I missing anything here? I am running this from an editor script, so maybe there is a bug there? I’ve read that people have made this work from editor scripts…


You should not use Instantiate in editor code unless that really is what you want to do. Instantiate just creates a clone of the source object and does not remember the prefab reference.

To create a prefab instance inside the editor you should use PrefabUtility.InstantiatePrefab.

Okay, with more debugging, it looks like this was an error on my part. There was another part of my script that was causing this issue. It looks like it works fine. Sorry to anyone who read through this.