Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Assassinbeast · Dec 06, 2013 at 12:16 AM · prefabinstance

Breaking a prefab doesn't break it completely?

Hello.

When i instantiate an object in a scene and break the prefab at GameObject -> Break Prefab Instance, then its not more blue in the hiearchy list, however, in the Inspector, i can still see that i can apply to the prefab.

So my question is, how do i break the prefab from my instance competely?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Dec 06, 2013 at 01:37 AM

As far as i know there's no way in the editor besides using Instantiate from an editor script to clone the object. I haven't tried it recently, so that might has been changed as well but used to work pretty well. When they introduced the "Break Prefab connection" button it fully disconnects the instance. I guess that most people complained that it's not possible to reconnect it. They renamed the button to "Break Prefab Instance" and now it's possible to reconnect to the prefab. So this is a quite recent change and i guess it's on purpose ;)

You can try PrefabUtility.DisconnectPrefabInstance in an editor script, but i guess that does the same as the menubutton. Instantiate used to do the job (actually it was a problem until we get PrefabUtility.InstantiatePrefab which lets you instantiate a prefab in the editor and preserve the prefab connection).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-1

Answer by SilverStorm · Nov 22, 2016 at 06:33 AM

Breaking a prefab requires you to select the game object in the scene and then going to the game object menu > break prefab connection. Then you can now safely delete the prefab asset in your project folder without your scene game object turning red.

If you do not want to delete the asset from your project folder then I think the revert option may likely remain in view. However I have not tried to rename my project folder asset after the breaking has occurred....their may still be a way.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by baci · Oct 14, 2015 at 02:48 PM

There seems to be no direct solution, which is why I created a small script that I attach to prefabs that I don't want to be changed from the hierarchy: It first breaks the prefab connection, then creates a temporary prefab in the Assets folder and connects the current object to that prefab. On Disabling, the prefab gets removed again. Seems very hacky, but works in my case.

Here is the code:

 using System.IO;
 using UnityEngine;
 using UnityEditor;
 
 /// <summary>
 /// This script can be attached to any prefab and prevents the prefab from being edited 
 /// and saved in the inspector view.
 /// This can be desired when changes to instances should not affect the prefab of the object.
 /// </summary>
 [ExecuteInEditMode]
 public class DisconnectPrefabOnSpawn : MonoBehaviour
 {
     private Object tmpObject;
 
     private void OnEnable()
     {
 #if UNITY_EDITOR
         if (!File.Exists(Application.dataPath + "/TMPPrefab.prefab"))
         {
             PrefabUtility.DisconnectPrefabInstance(gameObject);
             tmpObject = PrefabUtility.CreatePrefab("Assets/TMPPrefab.prefab", gameObject, ReplacePrefabOptions.ConnectToPrefab);
 
             //Destroy(this);
         }
 
 #endif
     }
 
     private void OnDisable()
     {
 #if UNITY_EDITOR
         if(AssetDatabase.Contains(tmpObject))
             AssetDatabase.DeleteAsset("Assets/TMPPrefab.prefab");
 #endif
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Bas-Smit · Mar 08, 2016 at 05:43 PM

 public static void RemoveDisconnectedReferences(string scenePath)
 {
     var lines = File.ReadAllLines(scenePath);
     var sb = new StringBuilder();
     var inPrefab = false;
     var removingDisconnectedPrefab = false;
 
     for (int i = 0; i < lines.Length; i++)
     {
         var line = lines[i];
 
         if (line.StartsWith("---"))
             inPrefab = lines[i + 1] == "Prefab:";
 
         if (inPrefab)
             sb.Append(line + "\n");
         else
         {
             if (line.StartsWith("  m_PrefabParentObject:"))
             {
                 sb.Append("  m_PrefabParentObject: {fileID: 0}\n");
                 removingDisconnectedPrefab = true;
             }
             else
             {
                 if (!(removingDisconnectedPrefab && line.StartsWith("    type:")))
                     sb.Append(line + "\n");
 
                 removingDisconnectedPrefab = false;
             }
         }
     }
 
     File.WriteAllText(scenePath, sb.ToString());
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by karmington · Feb 14, 2018 at 11:12 PM

Prefab breaking Editor script solution also here, confirmed working at Dec 20, 2017 : https://forum.unity.com/threads/breaking-a-prefab-instance-for-good.501919/

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing the Variables of An Instanced Script 2 Answers

How to refer to a collision between clones of the same prefab? C# 1 Answer

Updating a variable on a script in an instanced object 1 Answer

What is the difference between grey and blue prefab ? 1 Answer

Importing instances via FBX and replacing with prefabs 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges