Persist
Saves the node's transform and enabled flag in save games.
component save.Persist
Try it
Save a node's position
The target moves from the gray mark to the blue one, then saves and loads once. Persist normally restores its saved position; the temporary save stays in memory.
Enable No Transform. The scene restarts, saves and loads again: the omitted transform comes from the scene at the gray mark instead. Reset restores transform persistence.
Starts the scene; open the example parameters to experiment.
Scene4 nodes
Scriptmain.aes
package demo
import "aego/save"
// Perform one real in-memory save and reload. OnLoad removes the temporary
// slot, so Reset and another Try run begin independently.
script PersistenceProbe {
var requested bool
var finished bool
func Update(dt float) {
if finished {
return
}
if !save.Exists("persist-demo") {
if !requested {
node.SetPosition(Vec2{2, 0})
save.Save("persist-demo")
requested = true
}
} else if requested {
// A newly loaded world waits for OnLoad instead of loading again.
save.Load("persist-demo")
}
}
func OnLoad() {
finished = true
save.Delete("persist-demo")
}
}
Fields
| Name | Type | Default | Description |
|---|---|---|---|
| No Transform | bool | false | Leaves the transform out of save games, for nodes whose position comes from elsewhere. |
| No Enabled | bool | false | Leaves the enabled flag out of save games. |
From a script
Persist marks a node for save games; the script decides when to save and load.
package game
import (
"aego/input"
"aego/save"
)
script QuickSave {
func Update(dt float) {
if input.KeyPressed(input.KeyF5) {
save.Save("quick")
}
if input.KeyPressed(input.KeyF9) && save.Exists("quick") {
save.Load("quick")
}
}
}
Script events
Scripts on a node with this component receive these events from the Saving module.
OnLoad— Runs after Ready on every script that has it when a saved game is loaded; read values with save.Get*.OnSave— Runs on every script that has it while a game is saved; write values with save.Put*.
Related guides
- Saving games A save holds what you mark as persistent, not the whole scene.