I have been able to save my generated prefab during run time, but not without issue. I had to avoid using some “creation code” in order to get it to save properly. To better understand Unity, I’m just wondering why.
Here is an example code and what happens:
if (Input.GetKeyDown(KeyCode.Space) == true)
{
GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
//UNCOMMENT THIS LINE AND THE MESHFILTER COMPONENT AND MATERIAL WILL BE MISSING
//float uselessVariable = obj.GetComponent<MeshFilter>().mesh.bounds.size.x;
//UNCOMMENT THIS LINE AND THE MATERIAL WILL BE MISSING
//obj.GetComponent<Renderer>().material.color = Color.red;
PrefabUtility.CreatePrefab("Assets/Resources/Prefabs/StarShips/" + "TestSavePreFab" + ".prefab", obj);
}
I can understand that altering the material will cause it not to save (you probably have to save the “new” material separately), but simply calling mesh.bounds.size will remove the filter? I don’t understand.