Save & Load Add-On
  • Welcome to Save & Load Add-On for FPS Engine!
  • BEFORE WE START
    • Early Considerations
    • Add-On Compatibility
    • List of Tutorials
  • GETTING STARTED
    • 01. Basic Set-Up
    • 02. Roadmap
  • CONTENT
    • 03. Content
      • 03.1 DataPersistence
        • DataPersistence_SO
        • DataPersistenceManager
        • FileDataHandler
        • GameData
        • GameDataManager
      • 03.2 Editor
      • 03.3 Item Registry
        • ItemRegistry
        • ItemRegistryEditor
        • ItemRegistryAssetProcessor
      • 03.4 Main Menu
        • SaveSlot
        • SaveSlotsMenu
      • 03.5 Objects Save Data
        • CustomSaveData
      • 03.6 Serialization
        • SerializableVector3
        • SafeSerializationBinder
      • 03.7 Triggers
        • SaveTrigger
        • LoadTrigger
        • ToggleAutoSave
      • 03.8 Type Registry
        • TypeRegistry
        • TypeToPrefabMappingDrawer
      • 03.9 UI
        • SaveLoadButton
    • 04. Shared Content for Add-Ons
      • ToastManager
      • WorkLight
  • HOW TO USE & GUIDES
    • Save & Load Games Programmatically
    • Saving Custom Data: Simple Method
    • Saving Custom Data: Advanced Method
    • Loading Custom Data
    • Saving Instantiated Objects
    • Save & Load System during Development
    • Working with Save & Load in Cowsins Manager
    • Uninstalling the Add-On: Fixing Errors
    • Type to Prefab Mappings in Game Data Manager
    • How to add Buttons to Save & Load a game
    • Non-Saveable Scenes
    • Loading Scenes & Load Player Data
  • FAQ
    • FAQ
  • SUPPORT
    • Support
Powered by GitBook
On this page
  • Properties
  • Considerations
  • Expanding CustomSaveData
  1. CONTENT
  2. 03. Content
  3. 03.5 Objects Save Data

CustomSaveData

Previous03.5 Objects Save DataNext03.6 Serialization

Last updated 1 month ago

The CustomSaveData class is a data container used for serializing and deserializing save data for game objects. It provides mechanisms for saving the relevant fields of an object to a JSON format and loading the saved data back into the object. This class supports saving data like the scene name, position, and the type of object, along with a dictionary of saved fields that contain other properties of the object. It uses the Newtonsoft.Json library for JSON serialization and deserialization.

The class also defines methods for saving and loading fields based on the [SaveField] attribute and supports custom handling for non-serializable types like Item_SO objects.

Properties

  • SceneName (string):

    • The name of the scene where the object is located. This is stored to filter out objects that do not belong to the current scene during loading.

    • Attributes: [JsonProperty] (Serialized as part of JSON).

  • Position (SerializableVector3):

    • The position of the object in the scene. This will be serialized into the JSON file if it is provided. If not provided, the property is ignored during serialization.

    • Attributes: [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] (Only serialized if the position is not null).

  • Type (string):

    • The name of the object's type. This is useful for associating the object with its prefab or type information when reloading. For more information, refer to & .

  • savedFields (Dictionary<string, object>):

    • A dictionary that stores the saved fields of the object. The keys are the field names, and the values are the field values to be serialized. This Dictionary is populated based on the variables with the attribute [SaveField] within the class.

Considerations

Ensure that any field you want to save in an object is marked with the [SaveField] attribute.

Special care is taken when handling non-serializable types, since they cannot be included directly in the Json file (e.g., Item_SO).

Expanding CustomSaveData

Expanding CustomSaveData is usually unnecessary, as it, along with the SaveField attribute, can store all serializable fields without additional coding.

However, implementing custom data processing can be beneficial if you need to save non-serializable data types.

In such cases,.

TypeRegistry
GameDataManager
here’s a detailed guide on how to handle this scenario