Databrain Documentation
databrain.ccDiscord
  • Welcome
  • Installation / Update
  • Interface
  • DataObject Property Drawer
    • No GUI Implemented - FIX
  • Getting started
  • Guides
    • Add data objects
    • Add data objects at runtime
    • Get initial data
    • Get/Set runtime data
    • Serialize DataObjects
    • Runtime Save & Load
    • Use custom serializer
    • Import
    • Search
    • Custom GUI
    • Custom GUI with Odin Inspector
    • Hierarchy Template
  • Separate DataObjects
  • Using Version Control
  • Attributes
    • DataObject attributes
    • Field attributes
  • API
    • DataLibrary
    • DataObject
  • FAQ
    • Databrain - FAQ
  • Add-ons
    • Events
    • Blackboard
    • Logic
      • Interface
      • Create Graph
      • Execute graph
      • Control flow execution in groups
      • Custom Nodes
        • Asynchronous execution
        • Node Attributes
      • Scene Components
      • Graph Events
      • Finite State Machine
        • Create custom Actions
        • Examples
        • State Machine Nodes
    • Stats
      • Achievements
      • Modifiers
      • Values
      • Progressions
      • Components
      • Nodes
    • Progress
      • Progress Settings
      • Progress Graph
      • Progress Resources
      • Runtime UI Setup
      • API
        • ProgressController
    • Techtree (LEGACY)
      • Techtree Manager
      • Techtree
      • TechtreeResource
      • Techtree UIBuilder
        • Custom Techtree Node Button
        • Tooltip
      • API
    • Localization
      • Localization Manager
      • Localization
      • Examples
      • Components
      • Import
      • API
    • Inventory
      • Getting started
      • Demo
      • Data setup
        • Inventories
        • Slot IDs
        • Items
          • Blueprints
          • Item rarities
        • Money
        • Loot tables
        • Events
      • Runtime UI
        • Setup
    • Dialogue
      • Getting Started
        • Demo
      • Dialogue runtime setup
      • Actors
        • Emotions
      • Localization
      • Audio
      • Animation
      • Variables
      • Custom theme
      • Import
      • Nodes
      • API
        • DialogueController
        • IDialogueUIControl
  • Changelog
    • Databrain - Changelog
      • 1.4.0
      • 1.3.2
      • 1.3.1
      • 1.3.0
      • 1.2.0
      • 1.1.0
      • 1.0.10
      • 1.0.9
      • 1.0.8
      • 1.0.7
      • <= 1.0.6
Powered by GitBook
On this page
  1. Guides

Use custom serializer

By default, Databrain uses the Newtonsoft Json library to serialize the data to a json file. It is possible though to serialize the data with a custom serializer such as Odin Serializer.

Simply use the API methods GetSerializableData and SetSerializedData.

Here's a simple example using Odin Serializer:

using OdinSerializer;

// The data library
public DataLibrary data;

public void Save()
{
    // Get the serializable data class from the data library
    var serializableData = data.GetSerializableData();
    
    // Use Odin Serializer to serialize the data
    byte[] bytes = SerializationUtility.SerializeValue(serializableData, DataFormat.Binary);
    // Write to a file
    System.IO.File.WriteAllBytes(System.IO.Path.Combine(Application.persistentDataPath, "saveFile.data"), bytes);
}

public void Load()
{
    // Load the file as bytes
    byte[] bytes = System.IO.File.ReadAllBytes(System.IO.Path.Combine(Application.persistentDataPath, "saveFile.data"));
    
    // Deserialize the data using Odin Serializer
    var serializableData = SerializationUtility.DeserializeValue<DataLibrary.JsonSerializeableClass>(bytes, DataFormat.Binary);
    
    // Set the data back to the data library.
    // This will load the complete data and also calls the OnLoaded event.
    data.SetSerializedData(serializableData );
}
PreviousRuntime Save & LoadNextImport

Last updated 1 year ago