Skip to content

Instantly share code, notes, and snippets.

@bruchmann
Created October 31, 2022 10:56
Show Gist options
  • Save bruchmann/614bfb38092205f03456ce82baef818c to your computer and use it in GitHub Desktop.
Save bruchmann/614bfb38092205f03456ce82baef818c to your computer and use it in GitHub Desktop.
GDScript Save-Game Example
extends CharacterBody2D
class_name Player
# […]
func compute_save_state() -> Dictionary:
var save_state: Dictionary = {};
save_state["equipped_gun"] = self.equipped_gun;
save_state["inventory"] = self.inventory;
return {"key": "player", "value": save_state}
extends Node
class_name SaveGame
func compute_save_state() -> Dictionary:
var persistable_nodes: Array = get_tree().get_nodes_in_group("persistable");
var save_state: Dictionary = {};
for node in persistable_nodes:
if not node.has_method("compute_save_state"):
continue;
var state_to_save: Dictionary = node.compute_save_state();
save_state[save_to_state.key] = save_to_state.value;
save_game_state(save_state);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment