- Home /
Scriptable object meta info is hidden, where did it go?
Situation: we use two engines to create games, in both engines we have the same game, to generate and store information about the layout in BOTH games, we use the ScriptableObjects generated in Unity, they are easy to read. For doing that we have the following:
[CreateAssetMenu(fileName = "Flow level", menuName = "Flow level")]
public class FFLevel : ScriptableObject {
public string Name;
public int total_paths;
public Int2dArray grid;
public bool has_walls;
public bool[] walls_right;
public bool[] walls_bottom;
}
[System.Serializable]
public class Int2dArray {
public int length;
public int x, y;
public int Width { get { return x; } }
public int Height { get { return y; } }
public int[] m;
}
This generates the .asset file with all the info we need:
//Ignored the non important parts like internal Unity Ids and such
m_EditorClassIdentifier:
Name: There are walls
grid:
length: 8
x: 2
y: 4
m: 0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffff
has_walls: 1
walls_right: 0100010001000000
walls_bottom: 0000000000000000
total_paths: 1
The problem: When I wanted to add a new custom structure ( Portals):
[CreateAssetMenu(fileName = "Flow level", menuName = "Flow level")]
public class FFLevel : ScriptableObject {
public string Name;
public int total_paths;
public Int2dArray grid;
public bool has_walls;
public bool[] walls_right;
public bool[] walls_bottom;
public bool has_portals;
public Portals portals = new Portals();
}
[System.Serializable]
public class Portals {
public int Length;
public int[] p1_y;
public int[] p1_x;
public int[] p2_y;
public int[] p2_x;
}
After doing so, the .asset file became empty, the information regarding the data structures is gonne but all the other stuff (internal Unity Ids and that) it's still there, yet all the information inside Unity's engine is kept untill I hit Play, I can see all the info in the Inspector window:
//Ignored the non important parts like internal Unity Ids and such
m_EditorClassIdentifier:
Name:
total_paths: 0
grid:
length: 0
x: 0
y: 0
m:
has_walls: 0
walls_right:
walls_bottom:
has_portals: 0
portals:
Length: 0
p1_y:
p1_x:
p2_y:
p2_x:
Where has all the info gone? What can I do to fix this, if it is even possible?
Answer by FranTapTapTales · Nov 21, 2019 at 03:10 PM
Okay, so... don't know exactly why, but when adding a bunch of structures (even being serialized by default) Unity starts to break and not mark the ScriptableObject as dirty and thus, not saving the changes when Unity is closed. To fix this I simply added a button to mark the ScriptableObject as dirty:
if (GUILayout.Button("Save")) {
EditorUtility.SetDirty(target);
}