Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Cubiquity and Data Serialization

Discussion in 'Scripting' started by Lorinthio, Sep 7, 2015.

  1. Lorinthio

    Lorinthio

    Joined:
    Aug 7, 2015
    Posts:
    39
    Hello Unity Community,

    I've been stumped on an issue did some searching and can't make sense of what I've found. Essentially the issue comes down to serializing data to save/load. The data I'm trying to serialize is the ColoredCubesVolumeData from the Cubiquity.

    What the exact issue boils down to is this, the VolumeData is marked as serialized

    Code (CSharp):
    1.  
    2. namespace Cubiquity
    3. {
    4.     [System.Serializable]
    5.     public sealed class ColoredCubesVolumeData : VolumeData
    6.     {    
    7.  
    So I figured, if I extracted this class out and tried to serialize/save it. In return load it into the same class object it would work out. However on serialization with this code snippet...


    Code (CSharp):
    1.         public void Save(){
    2.             ColoredCubesVolumeData data = obj.GetComponent<ColoredCubesVolume> ().data;
    3.             BinaryFormatter bf = new BinaryFormatter();
    4.             FileStream file = File.Create (Application.persistentDataPath + "/" + obj.name + ".chunk");
    5.             bf.Serialize(file, data);
    6.             file.Close();
    7.         }
    I recieve the unity error that state I can't serialize the class object.

    I'm not sure how to proceed, except with abandoning Cubiquity and shelling $$$'s out as well as tears.
     
  2. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    I guess VolumeData inherits from ScriptableObject? If so the .Net/Mono serialization will have none of it. ScriptableObject isn't serializeable.

    To get round that, I suggest you could make a new container object that is serializeable and copy out fields you need from ColoredCubesVolume object, and write that to disk. Then when you start up, you could do the opposite - read the container object then assign the fields back to the ColoredCubesVolume instance.

    Or maybe check out Unity serialization, although I think it lives in the UnityEditor namespace which means it wont work in builds.

    Just some braindump!
     
  3. Lorinthio

    Lorinthio

    Joined:
    Aug 7, 2015
    Posts:
    39
    Ah I was hoping I was just having a brain fart and missing an obvious fix. But the "alternate - container" idea would work. Just more conversion work I was hoping to avoid =(
     
  4. bigd

    bigd

    Joined:
    Feb 14, 2014
    Posts:
    40
    Cubiquity stores its data in a sqlite database, typically called a vdb. This is already serialized to my understanding and can be treated as much. If your looking to implement a save / load system, all you would need to do is change the data to Read/Write mode, commit the changes, and your vdb will have all your changes included. When loading, just reference that file.

    Hopefully that makes sense. I'd also, if you haven't already, check out the support forum for Cubiquity for more answers.
     
    Last edited: Sep 16, 2015