x


Breaking a prefab connection

Is there a way to break a prefab connection through the editor? If I delete the prefab, the instance of it turns red and seems to want the underlying prefab restored. As it is, the only option seems to be to first delete one of the instance's components (or add one), which causes the editor to warn you that you're losing the connection. Then it's safe to delete the prefab.

Is there a more straightforward way to do this?

more ▼

asked Feb 05 '10 at 11:04 PM

Ehren gravatar image

Ehren
4.6k 35 43 77

A more explicit and direct way to do this on a single object without toying around with components would be extremely useful as certain plugins (I'm looking at EZ GUI) get really messed up when you duplicate objects in the hierarchy to be used as new prefabs.

Mar 23 '11 at 12:44 AM sampenguin

Since this is old, I'll add this here. GameObject>Break Prefab Instance, see my answer below.

Jun 25 '12 at 12:10 AM christo1745
(comments are locked)
10|3000 characters needed characters left

7 answers: sort voted first

Are you looking for "GameObject>Break Prefab Instance" in the menu?

more ▼

answered Mar 01 '12 at 09:31 PM

SGage gravatar image

SGage
436 1 1 1

Is that a Unity 3.5 feature? I'm not seeing it in my verson of Unity Pro

Mar 08 '12 at 09:12 PM kalvinlyle

Possibly, I've been using 3.5 for a while now so I can't remember

Mar 09 '12 at 09:53 AM SGage

it is a 3.5 feature

Mar 13 '12 at 02:01 PM SMillard

LOL totally awesome answer, thanks!

Jun 22 '12 at 02:17 PM Fattie

Cheers! I've been using Unity for a few years and I had missed that menu option. I'd always tried to add components until it popped up to tell me that would break the prefab.

Jul 24 '13 at 10:42 PM perchik
(comments are locked)
10|3000 characters needed characters left

You can use the PrefabUtility.DisconnectPrefabInstance function to do that:

http://unity3d.com/support/documentation/ScriptReference/PrefabUtility.DisconnectPrefabInstance.html

more ▼

answered Mar 09 '12 at 12:23 AM

ricardo_arango gravatar image

ricardo_arango ♦♦
10.7k 5 11 20

(comments are locked)
10|3000 characters needed characters left

EDIT This answer is obsolete as of Unity 3.5, see accepted answer.

It's not a direct command, but if you modify the object derived from the prefab, you will be asked if you want to break the connection. You could make a small, reversible change, agree to break the prefab connection and then reverse the change. Then, if you delete the prefab, the object is no longer strictly an instance.

more ▼

answered Feb 09 '10 at 05:03 PM

andeeee gravatar image

andeeee ♦
1.5k 3 6 18

Thanks, andeeee. I was aware of this option, but was wondering if there were another that was more straightforward. Sounds like this is it.

Feb 09 '10 at 06:09 PM Ehren

You could create an editor script for a menu item that adds a component to the instance and then removes it again. This ought to break the prefab connection (haven't tested ...).

Jan 27 '11 at 07:07 PM yoyo

You should be able to make an empty game object a child to break the prefab and then delete it.

May 02 '11 at 06:00 AM rafefx

If the GameObject is already in PrefabType.MissingPrefabInstance state, i.e. text reddened in the Hierarchy view, the only thing one can do to fix it (whiten it again) seems to be: 1. Create a new empty prefab, and replace it with the GameObject. 2. Modify the GameObject to disconnect it from the linked prefab. 3. Modify the GameObject back to how it was. 4. Delete the prefab created in step 1.

These can be done in an editor script, but it's just quite wrong isn't it?

May 15 '11 at 07:52 AM caroparo
(comments are locked)
10|3000 characters needed characters left

This works - I've tried it. However be warned that it will active gameObjects and their children. So what I did was store the list of active values for the whole hierarchy and then reapply the active values on the clone

string name = prefabedGO.name;
Transform parent = prefabedGO.transform.parent;
prefabedGO.transform.parent = null; // unparent the GO so that world transforms are preserved
GameObject unprefabedGO = (GameObject)Object.Instantiate(prefabedGO); // clears prefab link
unprefabedGO.name = prefabedGO.name;
unprefabedGO.active = prefabedGO.active;
DestroyImmediate(prefabedGO); // or this could just hide the old one .active = false;
unprefabedGO.transform.parent = parent;
more ▼

answered Oct 26 '11 at 09:10 PM

Rod Green gravatar image

Rod Green
3.1k 3 11 44

(comments are locked)
10|3000 characters needed characters left

Hrmmm. This is still a troublesome thing. Here's my ping to the question and a hopefully a clarification of the pain this brings. And perhaps a start on how to fix it. Imagine this... I made some an awesome prefab (pappy) that has lots of handy and complicated children (kiddos). I then copy a kiddo and paste it as a child to my new collection (newHotness). Now I am secretly screwed (trouble to silently appear later).

So I have:

pappy   (a prefab)
  kiddo1
  kiddo2
  koddo3

and

newHotness
  kiddo2
  newKid

I create a prefab out of newHotness (cause I'm like that).

Later I'm working on newHotness and I notice that I need to Apply my edits to the newHotness prefab. Sadly, I had kiddo2 selected and it applies my edits to kiddo2 back to the pappy prefab!

Whaaaaaat?!@#?!@?

I finally figure out that the prefab connection (like a sort of plague-like infection) has come along for the ride. kiddo2 never forgets who pappy was. Let's call it the "eternal inappropriate connection." What I desire more than root beer itself is a script that will let me remove the "eternal inappropriate connection" so that kiddo2 can go live his own new life as a member of the newHotness prefab. Anyone know some magic? Ultimately we need a new button next to Select, Revet, Apply, called "Unlink." For now, we make a specialized script:

[MenuItem("GameObject/Unlink Prefab")]
static void UnlinkPrefab() 
{
    foreach( GameObject g in Selection.gameObjects )
    {
       UmmmmmmLikeBreakThatPrefabLinkSomehow( g );
    }
}

Anybody have a guess for what UmmmmmmLikeBreakThatPrefabLinkSomehow() should be? -Ken =]

more ▼

answered Oct 11 '11 at 07:37 PM

kenlane22 gravatar image

kenlane22
41 1

PrefabUtility.DisconnectPrefabInstance ??

Mar 08 '12 at 09:12 PM kalvinlyle

Looks like I got what I hoped for for Christmas in Unity 3.5 in the "GameObject -> Break Prefab Instance" menu. Thanks for the code and UnityEditor tips, guys. I'll use both. Lots of goodies deep under the hood in 3.5 for we who keep the pipeline from sucking. -Ken =]

Mar 13 '12 at 08:17 PM kenlane22
(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:

x2372
x1828

asked: Feb 05 '10 at 11:04 PM

Seen: 27402 times

Last Updated: Dec 17 '13 at 09:33 PM