- Home /
Referenced script behaviour is missing only when overwriting prefabs ?
I have made a simple editor for something I am working on and everything seems to work fine, but when I save a prefab over an existing one I get a console full of
The referenced script on this Behaviour is missing! UnityEditor.PrefabUtility:CreatePrefab(String, GameObject) IOHandler:SaveTilesAsPrefab(GameObject, String) (at Assets/Scripts/IOHandler.cs:86) AddTiles:Update() (at Assets/Scripts/AddTiles.cs:597)
It doesn't seem to matter if the prefab is in the scene or not, and it doesn't actually seem to break anything.. I'm not a fan of debug errors though...
The number of times that I get the error seems to equal the number of scripts on the prefab I am overwriting as opposed to the number of scripts in the new prefab e.g. save a file with 6 scripts, overwrite it with a prefab with 10 scripts I will get 12 errors.. overwrite again with a prefab of 4 scripts I will get 20 errors etc, so I assume it is a case of I should be deleting the prefab first then saving ?.. not sure how to go about that.
The code I am using to save the prefab is
// Prefab Saver ----->
public void SaveTilesAsPrefab (GameObject objectToSave, string saveName)
{
// For some reason the sphere material goes null when I save the prefab..
// could be because I manually set .material.EnableKeyword ("_EMISSION")
GameObject[] tileDataSpheres = GameObject.FindGameObjectsWithTag ("tag_TileData");
foreach (GameObject GO in tileDataSpheres)
{
GO.GetComponent<Renderer>().material = sphereMat;
}
// Load the save file in project window
#if UNITY_EDITOR
string path = UnityEditor.EditorUtility.SaveFilePanelInProject ("Save Prefab", saveName + ".prefab", "prefab", "Enter a name for the prefab");
if (path.Length != 0)
{
// Seems to delete the file but still get the errors even if createprefab is disbled.. very odd ;)
UnityEditor.AssetDatabase.DeleteAsset(path);
UnityEditor.PrefabUtility.CreatePrefab (path, objectToSave);
}
#endif
}//<----- Prefab Saver
This is all new to me, so sorry in advance if I am being a bit dim :)
Edit: hmmm, I tried adding UnityEditor.AssetDatabase.DeleteAsset(path); just before the CreatePrefab line and still get the errors..