Question by
Sounds-Wonderful · May 13, 2018 at 12:22 PM ·
prefabprefab-instance
Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.
I read through the other answers.
I tried GameObject -> Break Prefab Instance
.
I tried
var objects = Resources.FindObjectsOfTypeAll<GameObject>().Where(obj => obj.name == "myPrafabName");
foreach (var m_prefab in objects)
{
Transform t = Instantiate(m_prefab.transform) as Transform; // instantiate prefab and get its transform
break;
}
I tried Duplicate
.
I tried
using UnityEngine;
using UnityEditor;
public class HardBreakPrefabInstance
{
const string TheMenuTitle = "GameObject/Hard Break Prefab Instance";
const string TheTempPrefabPath = "Assets/Temp/temp.prefab";
[MenuItem(TheMenuTitle)]
static void HardBreakPrefab()
{
if (Selection.transforms.Length == 1)
{
// Takes care of the annoying Select button that is left in the inspector
// after a single prefab is broken
GameObject go = Selection.activeGameObject;
Selection.activeObject = null;
DisconnectObject(go);
Selection.activeObject = go;
}
else
{
foreach (Transform tr in Selection.transforms)
DisconnectObject(tr.gameObject);
}
AssetDatabase.Refresh();
}
static void DisconnectObject(GameObject go)
{
Object prefab = PrefabUtility.CreateEmptyPrefab(TheTempPrefabPath);
PrefabUtility.ReplacePrefab(go, prefab, ReplacePrefabOptions.ConnectToPrefab);
AssetDatabase.DeleteAsset(TheTempPrefabPath);
PrefabUtility.DisconnectPrefabInstance(go);
}
/// <summary>
/// Validates the menu.
/// </summary>
/// <remarks>The item will be disabled if no game object is selected.</remarks>
[MenuItem(TheMenuTitle, true)]
static bool ValidateHardBreakPrefab()
{
return Selection.activeGameObject != null;
}
}
Still I get the message when trying
gameo.transform.SetParent(gameo2.transform);
Comment