What is the best way of serializing a big array of a class, that will be loaded when the game starts?
Right now i’m doing this, storing everything in a scriptable object.
public class MeshData : ScriptableObject, ISerializationCallbackReceiver
{
[SerializeField]
[HideInInspector]
internal Tiles[] tiles;
[SerializeField]
[HideInInspector]
internal Vertex[] vertices;
[SerializeField]
[HideInInspector]
internal Triangle[] triangles;
public void OnBeforeSerialize()
{
if (triangles != null && Ready)
{
_serializing = true;
SerializeTriangles();
_serializing = false;
}
}
public void OnAfterDeserialize()
{
_serializing = true;
DeserializeTriangles();
_serializing = false;
}
}
It works as expected, tiles and vertices have only serializable ints and floats and they dont need a custom serialization, but triangles have pointers to vertex and to other triangles, so they need that serialization step. It works.
Only problem is, it takes a few seconds to load every time the game starts. Array sizes are of about 256x256 = 65536 for the tiles, which hold a float, a int and a bool each, and about 500 to 1000 vertices, and 1000 to 2000 triangles. Vertices have only 2 floats each. Triangles carry a lot of data, something like 20 to 30 floats or ints each.
- Should i worry about this start loading time? Is it normal? It takes up to 5 seconds.
- Is there a better way of storing these other than in a scriptable object?
- When using scriptable objects, should they be stored in a prefab? Or is it fine to leave them as a field on a object that is on the hierarchy. (See screenshot, that is all and the only reference there is to the scriptable object. no prefabs created, no nothing. The mesh class has a meshData variable which gets assigned to the MeshData.