Hey everybody,
I’m basically creating some basic voxel-style map editor for myself. However I want to include a save/load System with it.
Right now I simply store the data in a three dimensional array of ScriptableObjects of VoxelType which right now has no properties on its own but is inherited by multiple other objects.
public class VoxelType : ScriptableObject
{
}
The Voxeltype is inherited by for example BlockType. The idea here being that the map can store things like blocks but also specific objects that just get spawned and not integrated into the voxel mesh.
public class BlockType : VoxelType
{
[SerializeField]
private bool _isOpaque;
public bool IsOpaque { get { return _isOpaque; }}
[SerializeField]
private Texture2DArray _textureArray;
public Texture2DArray TextureArray { get { return _textureArray; } }
....
public VoxelType[,,] voxels;
Here however I was wondering how to best create a save/load system for this kind of data.
I think I won’t be able to simply serialize the array itself, as it is just filled with references to scriptable objects.
I was considering to store the ID or the name of the specific ScriptableObject(e.g. "GrassBlock1) during saving and using either a “VoxelDatabase” ScriptableObject to store the references or use Adressables (if that would be a good use-case).
Also i wonder how to store serialize the data as the way my mapdata works right now is polymorphic.
BlockType derived from VoxelType will most likely have different fields then for example
ObjectType (like a door or a trap) also derived from VoxelType would have… Not too mention something like “directionalObjecttype” that could fit multiple objects into the same block-space (think signs like in minecraft in which you can have multiple signs in the same blockspace.
Apart from all this regards saving/loading I was wondering if using Scriptable Objects for my Voxeltypes might be a slower solution compared to just using indicies and a static lookup object.