- Home /
ScriptableObject Asset corrupted after reload of Unity
How it should look like.How it looks like after reload of Unity.
Here is the ScriptableObject:
public abstract class ISplineMesh : ScriptableObject
{
public Vector3[] verts;
public Vector3[] normals;
public Vector2[] uvs;
public float[] uvBounds = new float[4];
public int[] tris;
public float Vdist;
public bool ok = false;
public abstract string ID
{
get;
}
public string label;
}
Here is how it is Saved:
private void SaveAsset()
{
string label = splineMesh.splineMesh.label;
AssetDatabase.DeleteAsset(Application.dataPath +
"/Plugins/Nick's Ultima/UltimaRoadGen/Resources/RoadTypes/" + label + ".asset");
if (label == null || label == "")
{
label = "Temp";
}
if (createNewAsset)
{
if (System.IO.File.Exists(Application.dataPath +
"/Plugins/Nick's Ultima/UltimaRoadGen/Resources/RoadTypes/" + label + ".asset"))
{
int count = 0;
while (System.IO.File.Exists(Application.dataPath +
"/Plugins/Nick's Ultima/UltimaRoadGen/Resources/RoadTypes/" + label + "_" + count.ToString() + ".asset"))
{
count++;
}
label = label + "_" + count.ToString();
}
}
Debug.Log("Saved asset as: "+label);
if (!System.IO.File.Exists(Application.dataPath +
"/Plugins/Nick's Ultima/UltimaRoadGen/Resources/RoadTypes/" + label + ".asset"))
{
AssetDatabase.CreateAsset(splineMesh.splineMesh,
"Assets/Plugins/Nick's Ultima/UltimaRoadGen/Resources/RoadTypes/" + label + ".asset");
}
splineMesh.splineMesh.label = label;
AssetDatabase.SaveAssets();
}
The interesting thing is that the file on the disk still exists and takes up 4kb of space! Edit: Saved Assets also don't work with Editor.ObjectField!
Answer by Bunny83 · Sep 03, 2017 at 11:59 AM
Uhm your class is an abstract class. Abstract classes can't be instantiated. Well, Unity's serializer partly managed to "forcefully" create an instance in memory, but it's generally not possible and not the intention of an abstract class.
Your code does not show if you actually may use a non abstract subclass. However since the MonoScript field is None you most likely used the abstract class
The actual class being saved is this one, it just contains a lot of code so I didn't want to include it.
Your answer
Follow this Question
Related Questions
Are all ScriptableObject assets included in the build? 4 Answers
Problem with ScriptableObject and Custom Editor 2 Answers
Is there a message to be listen to when editor enter play mode? 2 Answers
Scriptable object meta info is hidden, where did it go? 1 Answer
Auto-refresh assets after changing scriptable object 0 Answers