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

ORK 4 Documentation

  • Getting Started
    • Welcome
    • First Steps (Unity)
  • Features
    • The Status System
    • Schematics
    • Schematic Nodes
    • Dialogue Importer
    • Variables
    • Selected Data
  • Components
    • Battle Components
    • Combatant Components
    • Control Components
    • Cursor Prefab Components
    • Game Starters
    • Interactable Components
    • Move AI Components
    • Scene Setup Components
  • Editor
    • The ORK 4 Editor
    • Sections & Sub-Sections
    • Node Editor
    • Schematic Editor
    • Asset Sources
    • Unity Overlay Toolbar
  • Section: System
    • System Settings
    • Languages
    • Organizer Types
    • Game States & Conditions
    • General Condition Templates
    • Object Pools
    • Prefab Savers
    • Scene Connections
  • Section: Controls
    • Game Controls
    • Interaction Settings
    • Player Controls
    • Camera Controls
    • Input Keys
    • Control Maps
    • Camera Positions
    • Battle Camera
  • Section: Gameplay
    • Game Settings
    • Formulas
    • Difficulties
    • Shortcut Slots & Settings
    • Custom Settings & Global Custom Settings
    • Global Machines
    • Machine Templates
  • Section: Status
    • Status Values
    • Status Effects
    • Attack Modifiers
    • Defence Modifiers
    • Abilities & Ability Developments
    • Status Developments
    • Research Trees
    • Damage Types
    • Status Bonuses & Templates
    • Status Condition Templates
  • Section: Inventory
    • Inventory Settings
    • Inventory Containers
    • Currencies
    • Items
    • AI Rulesets
    • Crafting Recipes
    • Equipment Slots & Slot Set Templates
    • Equipment & Available Equipment Templates
    • Shops
    • Loot
  • Section: Combatants
    • Combatants
    • Combatant Groups
    • Class Slots
    • Classes
    • Factions & Faction Benefits
    • Animations
    • Move AIs
    • Formations
    • Action Combos
  • Section: Battles
    • Battle Systems
    • Turn Based Battles
    • Active Time Battles
    • Real Time Battles
    • Phase Battles
    • Battle Spots
    • Battle AIs
    • Battle Actions Settings
    • Special Commands Settings
    • Target Settings
    • Target Selection Templates
    • Battle Range Templates
    • Battle Grid Settings
    • Battle Grid Highlights
    • Battle Grid Cell Types
    • Battle Grid Formations
  • Section: Content
    • Content Types
    • Music
    • Sound Templates
    • Areas
    • Teleports
    • Quests & Quest Tasks
    • Logs & Log Texts
    • Object Contents
  • Section: UI
    • UI Settings
    • UI Layers
    • UI Layouts
    • UI Boxes
    • HUDs
    • Notifications
    • Cursor Settings
  • Section: Menus
    • Start Menu
    • Save Game Settings
    • Option Categories
    • Menu Screens
    • Menu Requirements
    • Battle Menus
    • Loot Dialogues
    • Item Collection
    • Combatant Selections
    • Quantity Selections
    • Shop Layouts
  • Section: Texts
    • Text Settings
    • Formatting Settings
    • Flying Texts
    • Use Cost Display
    • Status Preview Display
    • Bonus Display
    • Status Change Display
    • Console Settings & Console Types
    • Text Codes
  • Sections: Editor
    • Editor Settings
    • Backups
    • Variables
    • Plugins
  • Scripting
    • Access Handler
    • Custom Nodes
    • Custom Save Data
    • Custom Component Save Data

ORK 4 Tutorials

  • ORK 4 Unity Quickstart Tutorials (3D)
    • ORK 4 Unity Quickstart 3D
    • 01 Initial ORK Setup
    • 02 Player Setup
    • 03 Music & Scenes
    • 04 UI System Setup
    • 05 UI Boxes
    • 06 Flying Texts
    • 07 Status Values
    • 08 Status Effects
    • 09 First Abilities
    • 10 Fighter Setup
    • 11 First Enemies & Battle AI
    • 12 Battle System Setup
    • 13 Animating Battle Start and End
    • 14 Random Battles
    • 15 Animating Actions
    • 16 Player Battle HUD
    • 17 Elemental Attacks
    • 18 Animating More Actions
    • 19 Inventory & Loot
    • 20 Equipment
    • 21 Loot, Start Equipment & Viewers
    • 22 Magic Abilities
    • 23 Caster Setup
    • 24 More Enemies
    • 25 Start Menu & Save Games
    • 26 Menu Screens
    • 27 Interactions
    • 28 Item Collectors
    • Quickstart Extended
  • Battle Tutorials
    • Adding Active Time Battles
    • Adding Phase Battles
    • Hit & Miss
    • Critical Hits
    • Cast Time
    • Grid 01: Battle Grid Setup
    • Grid 02: Highlights
    • Grid 03: Cell Types
    • Grid 04: Move Command
    • Grid 05: Scene Grid Setup
    • Grid 06: Battle Ready
    • Grid 07 Use & Affect Ranges
    • Grid 08: Better Camera Control
  • Gameplay Tutorials
    • Multiple Interaction Controllers
    • Player Group Spawn & Follow
    • Spawn Hunting Enemies
    • Gamepad Controls (Unity Input System)
    • Combined Inputs
    • Quests 01: Menu Screen
    • Quests 02: Hunting
    • Quests 03: Collect Potion Materials
    • Quests 04: Collect Equipment Materials
    • Quests 05: Quest Mark HUDs
    • Crafting 01: Menu Screen
    • Crafting 02: Materials & Recipes
    • Crafting 03: Getting Materials
    • Crafting 04: Proficiency & Critical Outcome
    • Shop
    • Inventory Containers
  • Schematics Tutorials
    • UI Animation Schematics
    • Flying Text Animation Schematics
    • HUD Conditional Schematics
  • UI Tutorials
    • Unity UI: Initial Setup
    • Unity UI: Status Value UI Setup
    • Unity UI: Status Effect UI Setup
    • Unity UI: Shortcut UI Setup
    • Unity UI: Dragging Notification
    • Unity UI: Interaction HUD
    • Unity UI: Shortcut HUD
    • Unity UI: Turn Order HUD
    • Unity UI: Cast Time HUD
    • Unity UI: Quest HUD
    • Unity UI: Tooltip HUD
    • Unity UI: Move Range HUD

ORK 4 Extensions

  • Plugins
    • Save Game Compression Plugin
  • Schematic Nodes
    • Footstepper Nodes (Unity)
  • Scripts
    • A* Pathfinding Movement Component (Unity)
    • PolyNav 2D Movement Component (Unity)
    • Cinemachine Camera Control Type (Unity)
    • Rewired Input Key (Unity)
    • Unity Legacy Input Key (Unity)
    • Core GameKit Wrapper (Unity)
    • Pool Boss Wrapper (Unity)
View Categories
  • Guide
  • ORK 4
  • ORK 4 Documentation
  • Scripting

Custom Component Save Data

Store component data attached to a combatant’s object and save it with ORK’s save game system.

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

This system is also supported when saving spawned prefabs using prefab savers or Object Saver components in your scenes.

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

When will the data be stored/loaded? #

Non-Combatant Objects #

The object needs to be a prefab instance registered with a prefab saver, or use an Object Saver component (and be part of the scene’s setup, i.e. not spawned during play).

The data of all components implementing the IComponentSaveData attached to a object or any of its children will be stored when the object is destroyed (including scene changes) or the game is saved while the object is alive.

The data is loaded when returning to the scene – again, when it was saved as a prefab saver or via an Object Saver component.

Combatants #

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

  • the object is destroyed
  • when a combatant is stored (while the 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 object isn’t alive at that time, the stored data (from destroying the object) will be saved

The data is loaded whenever the combatant’s prefab is spawned or a new object is assigned as the combatant’s 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 (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 (Unity) #

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

using UnityEngine;
using GamingIsLove.ORKFramework;

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 custom save data documentation for details.

Table of Contents
  • When will the data be stored/loaded?
    • Non-Combatant Objects
    • Combatants
  • The IComponentSaveData interface
    • GetSaveKey Function
    • SaveGame Function
    • LoadGame Function
  • Code example (Unity)
  • Saving Complex Data
Sitemap
  • ORK 4 BETA
  • Features
  • Showcase
  • Guide
    • Documentation
    • Tutorials
    • API
  • ORK 2 Hub
    • Tutorials
    • Plugins
    • API
  • Support
  • Forum
  • Get ORK
  • Contact
  • Blog
  • Makinom
  • gamingislove.com
Categories
  • News (73)
  • ORK 2 (137)
    • Tutorial (137)
      • Game tutorial (50)
      • Gameplay (32)
      • How-to (55)
  • Release (156)
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!