Search Unity

[RELEASED] Databox - Data editor & save solution

Discussion in 'Assets and Asset Store' started by propeller, Oct 30, 2019.

  1. propeller


    Jul 2, 2012
    Did you update to the newest version? Databox does not save the data to an asset... it uses Odin or FullSerializer to save all the data to a file (json or binary)

    Please follow the installation instructions:

    Hi sorry for not being so active here!
    Unfortunately the forum refuses to notify me about new posts.
    You can also join the Discord server:

    I'm more active here and you can also get help from the community :)

    A Databox object is already a scriptable object. Not sure why you want to add and nest it in another scriptable object?
    The idea of copying the data to the persistent data folder is to make sure the user has got all the data on his machine. So when modifying values it will be saved on the users machine. This is important because when updating your game the saved data will remain in the persistent data folder. Streaming Assets would replace the saved values on the users machine, when the game gets updated.
    MrIconic likes this.
  2. peeka


    Dec 3, 2014
    can you add support for ulongtype? or would it work if I add it myself? why is it missing in the first place?
  3. Sky_Higher


    Sep 29, 2017
  4. burlingk


    Dec 28, 2014
    Something I have not found stated anywhere, one way or the other: Does Databox support Linux? Can I use this in a project that is intended to support Linux as well as Windows?

  5. oliverashford


    Jan 27, 2016
    I have recently purchased Databox and it is working great - the documentation has got me up and running with some basic examples quickly. Appreciate the great resource!

    I am creating a choose your own adventure game and am storing the immutable 'book' data in Databox. Previously I have been hand writing all the content in JSON then parsing in Unity and building nested, custom objects. What I really want to do is use Databox as an 'in unity' editor for this content. This will require me to create nested custom classes to be serialised by Databox and displayed in the Unity UI - is this possible?

    An simple pseudo code example of my structure:

    Code (JavaScript):
    2. {
    3.     "bookTitle": "The Wizard Of Firetop Mountain",
    4.     "pages": [
    5.         {
    6.             "pageRefId": 0,
    7.             "pageTitle": "Rumours",
    8.             "pageAmbientAudio": "pageAmbientAudio_forest",
    9.             "pageText": [
    10.                 "Only a foolhardy adventurer..."
    11.             ],
    12.             "pageOptions": [
    13.                 {
    14.                     "optionText": "Now Turn over",
    15.                     "optionType": "New Page",
    16.                     "optionTarget": 1
    17.                 }
    18.             ]
    19.         },
    20.         {
    21.             "pageRefId": 156,
    22.             "pageAmbientAudio": "pageAmbientAudio_cave",
    23.             "pageText": [
    24.                 "You charge the door with your shoulder."
    25.             ],
    26.             "pageOptions": [
    27.                 {
    28.                     "optionText": "Charge!",
    29.                     "optionType": "Test"
    30.                 }
    31.             ],
    32.             "pageAction": {
    33.                 "actionText": "Roll two dice. If the number rolled is less than or equal to your skill score, you succeed. If the number rolled is greater than your skill, you rub your bruised shoulder and decide against trying again. You return to the junction.",
    34.                 "actionType": {
    35.                     "actionDice": "Two Dice Roll",
    36.                     "actionAgainst": "Skill",
    37.                     "actionOperator": "Less Than Or Equal"
    38.                 },
    39.                 "actionResult": {
    40.                     "actionPassed": 343,
    41.                     "actionFailed": 92
    42.                 }
    43.             }
    44.         },
    45.         {
    46.             "pageRefId": 248,
    47.             "pageAmbientAudio": "pageAmbientAudio_cave",
    48.             "pageText": [
    49.                 "The creature that has just awakened is an ORC! He scrambles to his feet and turns to grasp at a rope which is probably the alarm bell. You must attack him quickly."
    50.             ],
    51.             "pageOptions": [
    52.                 {
    53.                     "optionText": "Attack!",
    54.                     "optionType": "Battle"
    55.                 }
    56.             ],
    57.             "pageBattle": {
    58.                 "battleEnemies": [
    59.                     {
    60.                       "enemyName": "Orc",
    61.                       "Skill": 6,
    62.                       "Stamina": 5
    63.                     }
    64.                 ],
    65.                 "battleResult": {
    66.                     "battlePassed": 301
    67.                 }
    68.             }
    69.         },
    70.         {
    71.             "pageRefId": 278,
    72.             "pageAmbientAudio": "pageAmbientAudio_cave",
    73.             "pageText": [
    74.                 "The passageway soon comes to an end at a locked wooden door. You listen at the door but hear nothing. Will you try to charge the door down or would you rather turn around and go back to the junction?"
    75.             ],
    76.             "pageOptions": [
    77.                 {
    78.                     "optionText": "Charge door down",
    79.                     "optionType": "New Page",
    80.                     "optionTarget": 156
    81.                 },
    82.                 {
    83.                     "optionText": "Turn around",
    84.                     "optionType": "New Page",
    85.                     "optionTarget": 92
    86.                 }
    87.             ]
    88.         },
    89.         {
    90.             "pageRefId": 301,
    91.             "pageAmbientAudio": "pageAmbientAudio_cave",
    92.             "pageText": [
    93.                 "To your left, on the west face of the passage, there is a rough-cut wooden door. You listen at the door and can hear a rasping sound which may be some sort of creature snoring. Do you want to open the door?"
    94.             ],
    95.             "pageOptions": [
    96.                 {
    97.                     "optionText": "Open the door",
    98.                     "optionType": "New Page",
    99.                     "optionTarget": 82
    100.                 },
    101.                 {
    102.                     "optionText": "Press on northwards",
    103.                     "optionType": "New Page",
    104.                     "optionTarget": 208
    105.                 }
    106.             ]
    107.         }
    108.     ]
    109. }
    As far as I understand it in Databox this would require me to setup something like this:
    • Add Databox
    • Add Table: "Pages"
    • Define custom class: "Page" with vars:
      • id - int
      • text - string -> TextArea
      • ambient_audio - AudioClip -> ObjectField
      • options - An Array/Dictionary of "Option" objects, another custom class
    And it's there that I get stuck - I don't have much experience with building editor extensions in Unity. I know what I want is a tree like nesting of Pages -> Options, Page -> Battle -> Enemies. Is this possible or am I trying to make Databox do something it's not designed for? Would Odin alone be a better / simpler solution?

    Any help greatly appreciated (apologies for the long post!)
  6. propeller


    Jul 2, 2012
    first of all I'm happy to hear you like Databox. :)
    Figuring out how to structure data is always a challenge, but yes you could use List or Dictionary of classes as long as they are serializeable.
    So basically you create a custom base class which inherits from DataboxType.
    In this base class you then have your Dictionaries or Lists which holds other classes.
    Of course you will then have to create the editor UI to draw the data correctly in Databox by yourself. There are some example types (also lists and dictionaries) which should point you in the right direction.

    You can also write me an email if you need further support.
    oliverashford likes this.
  7. oliverashford


    Jan 27, 2016
    Thanks for getting back to me - that was really helpful. Have that issue sorted now.
  8. oliverashford


    Jan 27, 2016

    A question about serialising AudioClips. I have this code:

    Code (CSharp):
    1. [SerializeField]
    2. private AudioClip _ambientAudio;
    3. public AudioClip AmbientAudio
    4. {
    5.     get { return _ambientAudio; }
    6.     set
    7.     {
    8.         if (value == _ambientAudio) { return; }
    10.         _ambientAudio = value;
    12.         if (OnValueChanged != null) { OnValueChanged(this); }
    13.     }
    14. }
    And then to 'draw' the GUI:

    Code (CSharp):
    1. // Draw AmbientAudio
    2. using (new GUILayout.HorizontalScope())
    3. {
    4.     #if UNITY_EDITOR
    5.         _ambientAudio = (AudioClip)EditorGUILayout.ObjectField(_ambientAudio, typeof(AudioClip), true);
    6.     #endif
    7. }
    This works for selecting the AudioClip in the Databox inspector but it isn't saving the value. I presume this is because, as it is json/text we need to save a resource path, name or reference as opposed to binary sound data... how do I do this?

    Thanks in advance.
  9. propeller


    Jul 2, 2012

    Yes, exactly. If you want to use the resource path you'll have to store the resource path of the asset as a string. You can have a look at the built-in ResourcesType which does exactly this.
    If you're using the new Unity addressables, you can also use the AddressablesType. -> You'll have to uncomment the code from the AddressablesType.cs file.
    oliverashford likes this.
  10. Skotrap7


    May 24, 2018
    Hi, I have a bunch of scriptable objects already defined (and some assets of those types) and I'm trying to switch over to using Databox. On the store page and documentation I see Scriptable Object mentioned a lot, but I don't see a clear way on how to use them with Databox.

    Do I need to abandon my scriptableobject classes and make them inherit from "DataboxType" instead? Or can I somehow have Databox serialize/deserialize data in and out of the scriptable objects?

    For the assets I can write a script to load them and save them in Databox, but I didn't want to make any changes to those classes until I knew what the right way to move forward here was.

    Lastly, my understanding of the entryid and valueid fields is that the entryid is a collection of a specific type and valueid is the items in the collection. Does that sound right?

    Thanks in advance!
  11. SweetBro


    Jan 14, 2013
    I see databox uses custom DrawEditor() to render custom classes. Is this compatible with Odin Inspector's editor rendering and if so is there a quick example you can show for a simple class consisting of just a foo/bar string?

    Essentially I want to make use of Odin's default rending for a lot of common fields so I don't have to constantly manually update draw logic to reflect changes in the data model.
  12. propeller


    Jul 2, 2012
    Let me try to explain it a bit more in detail:
    So with Databox you create a Databox object which is a scriptable object asset.
    Inside of this Databox object you can add your data. This data can be custom classes, but they have to derive from DataboxType. All data inside of a Databox object is then serialized to a file. So to answer your first question: Yes you would have to derive your custom classes from DataboxType in order to add them to a Databox object.

    An entry is a collection of different types and values are the actual "variables" containing value.
    Example: Entry -> Player
    Player entry has multiple different values like: Health (int), Name (string) etc.
  13. propeller


    Jul 2, 2012
    Unfortunately odin inspector is not supported. And I'm not sure if I could ever make it work with Databox.
    I plan to add some custom variable attributes to quickly draw custom editor gui though.
  14. Skotrap7


    May 24, 2018
    Hey thanks for the reply, this helps a lot and gives me a path forward.
  15. tompio


    Jan 14, 2020
    Hello! Am I the only one, who can't find any option to create a DataObject? I just blocked on the very first step of getting started with this addon...

    Attached Files:

  16. xiao-xxl


    Nov 16, 2018
    Does it support Unity 2018 ?
  17. thejinxiest


    Apr 19, 2017
    Alright, lets necro this thread in hopes it helps someone out there!

    I've just experienced this. Was seemingly resolved by following the advice of unity's error log; changing your Api compatibility to .NET 4.x

    • Edit > Project Settings
    • 'Player' menu item (in the left-hand panel)
    • Set 'Api Compatibility Level' to '.NET 4.x'
    Databoxes components are not available by right-clicking the hierarchy. Instead you'll have to go to Assets > Create > Databox.
  18. xiao-xxl


    Nov 16, 2018
    Hello, can databox save dictionary? Can databox work with xml? My game is saved by xml now. And i want switch it to your databox. Is there a very simple and fast way to do this?
  19. propeller


    Jul 2, 2012
    Always recommended to read the documentation ;)

    Databox can serialize Dictionaries. There's also an example class with a Dictionary<string, string>. If you need any custom dictionaries with custom serializable types you'll have to create your own Databox type class.
    Databox supports FullSerializer and Odin serializer. FullSerializer supports json. Odin supports json and binary. XML is not supported.
  20. Andrew_ake


    Aug 19, 2018
    about 'Api Compatibility Level' and Odin.
    in the latest version (1.2.0) if I choose to go with FullSerializer and NET 2. and delete OdinSerializer I get following error:
    Assets\Databox\Types\DataboxType.cs(6,15): error CS0234: The type or namespace name 'OdinSerializer' does not exist in the namespace 'Databox' (are you missing an assembly reference?)
    and sure - there is "using Databox.OdinSerializer;" in DataboxType.cs
    It wasn't there before (at least in version 1.1.3 I think)
    Will be deleting this string suffice or should I do something more?
  21. Dragonname


    Jun 25, 2015
    Would it be possible to use playfab with this asset. I want to use their data storage instead of building my own mysql database because they offer many other services.
  22. Skotrap7


    May 24, 2018
    The new Scheme feature is pretty nice, but I have a question/suggestion/feature request.

    Rather than having to define a Scheme and every field in it that would then need to be read individually out of the databox object, it would be nice to allow a scheme to be a class and be able to retrieve the entire object.

    For example: Define an Armor class like this:

    Code (CSharp):
    1. [Serializable]
    2. class Armor : DataboxType
    3. {
    4.    [SerializedField]
    5.    private string _name;
    7.    [SerializedField]
    8.    private string _description;
    10.    [SerializedField]
    11.    private Slot _slot; // an enum
    12.    public override void DrawEditor()
    13.    {
    14.         // my editor code...
    15.    }
    16. }
    Then define a scheme with the name "Armor Scheme" and the "Type" as the above Armor class. Then I could create a table "Armors" in the databox object, add the Scheme "Armor Scheme" and just fill in those fields. Later, at runtime when I need to create some armor loot I can just do something like:

    Code (CSharp):
    2. Armor loot = _databoxObject.GetData<Armor>("Armors", "Helmet 1", "Armor Scheme");
    Also, your documentation doesn't specify exactly how to get data when using a scheme... I'm assuming the "Value Name" in the last parameter of the GetData function corresponds to the "Name" of the type in the Scheme. Is that right?
  23. propeller


    Jul 2, 2012
    This is already possible with Databox. In fact every databox type is made with a custom class.
    You can of course also add mutliple values to one class, you just have to make sure to draw them all in the DrawGUI method. Please have a look at the "Example Class", there you can see how one class can contain multiple fields.

    A scheme is just a "blueprint" for Databox which describes what kind of data classes should be added to the database. Retrieving the data works like any other class: GetData<MyType>("Table", "Entry", "Value");