ORK Framework Logo - RPG Editor for Unity
  • Features
  • Showcase
  • Guide
    • Documentation
    • Tutorials
    • API
  • ORK 2
    • Tutorials
    • Plugins
    • API
  • Support
  • Forum
  • Get ORK

Getting Started

  • Introduction
  • First Steps
  • Game Starters
  • Components Overview
  • Player/Camera Controls
  • Game Over

Editor

  • Editor Overview
  • Base/Control Section
  • Game Section
  • UI Section
  • Templates Section
  • Status Section
  • Inventory Section
  • Combatants Section
  • Battles Section

Features

  • Animations
  • Areas & Teleports
  • Combatant Triggers
  • Control Maps
  • Difficulties
  • Factions
  • Formations
  • Formula Nodes
  • Logs
  • Loot
  • Move AI
  • Quests
  • Research Trees
  • Schematic Nodes
  • Shortcut Slots

Status System

  • Status Values
  • Status Effects
  • Attack/Defence Modifiers
  • Abilities
  • Combatants
  • Classes
  • Status Bonuses
  • Status Conditions

Inventory System

  • Inventory System Overview
  • Currencies
  • Items
  • Equipment
  • AI Behaviours/Rulesets
  • Crafting Recipes
  • Shops

Battle System

  • Battle Systems
  • Adding Battles to Scenes
  • Calculating Action Results
  • Battle Menus
  • Battle AI
  • Battle AI Nodes
  • Battle Ranges
  • Battle Camera
  • Target Selection
  • Battle Spots
  • Battle Texts
  • Battle End & Loot Dialogues
  • Action Combos
  • Damage Types
  • Cursor Prefab Components
  • Grid Battles
  • Adding Battle Grids to Scenes
  • Battle Grid Highlights
  • Battle Grid Formations

UI System

  • UI System Overview
  • Start Menu
  • Menu Screens
  • Notifications
  • Combatant Selections
  • Quantity Selections
  • Text Display Settings
  • Cursor Settings
  • Console (In-Game)
  • Menu Requirements
  • HUDs: Content Providers
  • HUDs: Conditions
  • HUDs: Click Actions
  • HUDs: Text Content
  • HUDs: Value Bar Content
  • HUDs: Status Values
  • HUDs: Status Effects
  • HUDs: Attack Modifiers
  • HUDs: Defence Modifiers
  • HUDs: Shortcuts
  • HUDs: Abilities
  • HUDs: Equipment
  • HUDs: Class Slots
  • HUDs: AI Behaviours
  • HUDs: AI Rulesets
  • HUDs: Quests
  • Timebar HUD

Scripting

  • Scripting Overview
  • Access Handler
  • Code Extensions
  • Combatant Scripting
  • Custom Nodes
  • Custom Component Save Data
  • Home
  • Guide
  • Documentation
  • Scripting
  • Custom Component Save Data

Custom Component Save Data

Table of Contents
  • When will the data be stored/loaded?
  • The IComponentSaveData interface
    • GetSaveKey Function
    • SaveGame Function
    • LoadGame Function
  • Code example
  • Saving Complex Data

ORK Framework can store component data attached to a combatant’s game object and save it with ORK/Makinom’s save game system.

This is done by implementing the IComponentSaveData interface in your component’s class.

You can also add custom save data (outside of components) – see the Makinom custom save data documentation for details.

This documentation focuses on the use for combatants, for a general use of the IComponentSaveData interface, please refer to the Makinom documentation. You can e.g. also save component data when using Prefab Savers and Game Object Savers, learn more about them in the saving game objects documentation.

When will the data be stored/loaded? #

The data of all components implementing the IComponentSaveData attached to a combatant’s game object or any of its children will be stored when:

  • the game object is destroyed
  • when a combatant is stored (while the game object is alive) through a Combatant Spawner component (using the Remember Combatants setting)
  • when the game is saved (only for members of the player group), if the combatant’s game object isn’t alive at that time, the stored data (from destroying the game object) will be saved

The data is loaded whenever the combatant’s prefab is spawned or a new game object is assigned as the combatant’s game object.

This can be used to e.g.:

  • save component data with a save game
  • transfer component data between scenes
  • transfer component data when changing prefabs (conditional prefabs)
  • store component data for remembered combatants (Combatant Spawners)

The IComponentSaveData interface #

The IComponentSaveData interface extends the ISaveData interface that’s the basis for all save data in ORK/Makinom (and also used in the custom save data handling).

This interface has 3 functions (2 inherited from the ISaveData interface) that need to be implemented into your class:

GetSaveKey Function #

This function returns the save key used to store the data of the component.

public string GetSaveKey()

The save key mustn’t contain any spaces, e.g. save key is not allowed, but save_key is allowed.

Only one component data can be stored per key, i.e. if you want to store multiple components of the same class, you should implement a save key field to define a save key in the inspector of the component and return that key in the function.

SaveGame Function #

This function is called when the component data is stored/saved. It returns a DataObject, which holds all the data that you want to save.

public DataObject SaveGame()

LoadGame Function #

This function is called when a component data is loaded.

public void LoadGame(DataObject data)

The DataObject passed as parameter contains the data that is saved. It’s crucial to make a check for null on the data object before using it, since it could be null if no data was found for the save key – in that case, you can use the load game function to do default initialization.

Code example #

Here’s a small code example on how the custom component save data functionality can be used.

using UnityEngine;
using GamingIsLove.ORKFramework;
using GamingIsLove.Makinom;

public class ComponentSaveTest : MonoBehaviour, IComponentSaveData
{
	// save key used to store different components of this class
	public string saveKey = "";


	// save values
	public bool toggle = false;

	public float number = 0;

	public string text = "";


	public string GetSaveKey()
	{
		return saveKey;
	}

	// called when the component data is saved/stored
	public DataObject SaveGame()
	{
		DataObject data = new DataObject();

		data.Set("toggle", this.toggle);
		data.Set("number", this.number);
		data.Set("text", this.text);

		return data;
	}

	// called when the component data is loaded
	public void LoadGame(DataObject data)
	{
		if(data != null)
		{
			data.Get("toggle", ref this.toggle);
			data.Get("number", ref this.number);
			data.Get("text", ref this.text);
		}
	}
}

Saving Complex Data #

You can also save the data from classes and class arrays within your custom save game data by implementing the ISaveData interface in the class. This allows creating complex save game structures.

Naturally you can also save classes within classes, within classes … there is no depth limit.

See the Makinom custom save data documentation for details.

Scripting
Share This Article :
  • Facebook
  • Twitter
  • LinkedIn
  • Pinterest
Updated on June 30, 2022
Table of Contents
  • When will the data be stored/loaded?
  • The IComponentSaveData interface
    • GetSaveKey Function
    • SaveGame Function
    • LoadGame Function
  • Code example
  • Saving Complex Data
Sitemap
  • Features
  • Showcase
  • Guide
    • Documentation
    • Tutorials
    • API
  • ORK 2 Hub
    • Tutorials
    • Plugins
    • API
  • Support
  • Forum
  • Get ORK
  • Contact
  • Blog
  • Makinom
  • gamingislove.com
Categories
  • News (60)
  • ORK 2 (137)
    • Tutorial (137)
      • Game tutorial (50)
      • Gameplay (32)
      • How-to (55)
  • Release (130)
Search

© 2015 Gaming is Love e.U.

Disclosure: This site may contain affiliate links, which means I may receive a commission if you click a link and purchase something that I have recommended. While clicking these links won’t cost you any money, they will help me fund my development projects while recommending great assets!