Restore destroyed Object
Bring back a single destroyed object—without reloading the whole scene. This guide shows the two common paths:
You still have the object reference or its UniqueID and just want to re‑apply saved state, or
The object was destroyed and you want Crystal Save to re‑instantiate it from the saved data.
Before you start
Make sure the object was being tracked:
Scene objects should have Remember Component (plus the helpers you care about, e.g., RememberTransform, RememberRigidbody, etc.).
Runtime prefabs should have SaveablePrefab.
The object must have a UniqueID (assigned automatically by the components above).
If you intend to respawn a destroyed prefab, that prefab must be known to Crystal Save (registered via SaveablePrefab / Prefab Registry).
Option A — “The object exists; just re-apply its saved state”
Use this when the GameObject still exists (maybe it moved, changed, or lost values) and you want to snap it back to what’s stored in a save slot.
If you have a reference to the object
using Arawn.CrystalSave.Runtime;
using UnityEngine;
public class RestoreOne : MonoBehaviour
{
[SerializeField] GameObject target; // e.g., boss door in the scene
[SerializeField] int slotNumber = 1;
public void RestoreNow()
{
SaveManager.Instance.RestoreSingleGameObject(target, slotNumber);
}
}
If you have a reference to the object
using Arawn.CrystalSave.Runtime;
using UnityEngine;
public class RestoreOne : MonoBehaviour
{
[SerializeField] GameObject target; // e.g., boss door in the scene
[SerializeField] int slotNumber = 1;
public void RestoreNow()
{
SaveManager.Instance.RestoreSingleGameObject(target, slotNumber);
}
}
If you only know the UniqueID (string)
using Arawn.CrystalSave.Runtime;
public class RestoreById
{
const string BossDoorID = "Door_BossRoom_003";
const int Slot = 3;
public void RestoreNow()
{
SaveManager.Instance.RestoreSingleGameObject(BossDoorID, Slot);
}
}
Re-apply from the currently loaded save (no slot I/O)
If you already loaded a save and just want to re-apply it:
SaveManager.Instance.RestoreSingleGameObject(existingGameObject);
Option B — “The object was destroyed; respawn it from the save”
Use this path when the target GameObject no longer exists in the scene (e.g., breakable crate, pickup, NPC).
Restore one destroyed object
using Arawn.CrystalSave.Runtime;
public class RespawnOne
{
const string CrateId = "Crate_TutorialRoom_05";
public void RespawnCrate()
{
SaveManager.Instance.RestoreDestroyedGameObject(CrateId);
}
}
Restore all destroyed objects that still map to a prefab
SaveManager.Instance.RestoreAllDestroyedGameObjects();
Guard restore with a check
string npcID = "Vendor_Myrna";
if (SaveManager.Instance.IsGameObjectDestroyed(npcID))
{
SaveManager.Instance.RestoreDestroyedGameObject(npcID);
}
Working from “latest save slot” (handy utilities)
If you don’t know which slot to use, these helpers pull from the most recent saved slot:
using Arawn.CrystalSave.Runtime;
using UnityEngine;
using System.Threading.Tasks;
public class OneClickRespawn : MonoBehaviour
{
public async void RespawnManyDestroyed(params string[] destroyedIds)
{
// Each ID can be a prefab instance UniqueID or the prefab asset ID,
// depending on how you saved it.
await SaveManager.Instance.RestoreSinglePrefabsFromMostRecentSlotAsync(destroyedIds);
}
public async void ReapplyForMany(params GameObject[] liveObjects)
{
// Re-apply saved state to existing objects from the newest slot.
await SaveManager.Instance.RestoreSingleGameObjectsFromMostRecentSlotAsync(liveObjects);
}
}
What exactly gets restored?
When Crystal Save restores a single object (existing or respawned), it:
Sets active state.
Restores Transform (position/rotation/scale).
Restores Rigidbody snapshot (kinematics, gravity, drag, velocities) if present.
Restores Animator state (layer-0 state hash + normalized time) if present.
Replays runtime modifications captured for SaveablePrefab (e.g., added components, mesh/material swaps, particle time/playing state, child edits).
Applies all Remember Component bytes (your per‑component helpers).
Common pitfalls & tips
Prefab must be registered To respawn a destroyed prefab, Crystal Save needs to know which asset to instantiate. Ensure the asset has SaveablePrefab (and is in the Prefab Registry if you manage it manually).
Track components you care about Add the corresponding Remember… helpers (Transform, Rigidbody, Animator, custom components). Only tracked data can be restored.
Use SaveablePrefabFactory for runtime spawns If you spawn prefabs yourself, prefer
SaveablePrefabFactory.Instantiate(...)
so instances get fresh UniqueIDs and registration out of the box.Child renames Don’t rename children of instantiated prefabs at runtime. Child names are used as part of identity for certain diffs.
Cloud Save timing When restoring from a slot while cloud save is enabled, make sure the player is signed-in (or that you’re using a local mirror). The targeted restore helpers already load the slot data asynchronously.
Minimal example: “Reset room” button
using Arawn.CrystalSave.Runtime;
using UnityEngine;
public class ResetRoomButton : MonoBehaviour
{
[SerializeField] string[] propsToRespawn; // UniqueIDs of destroyed props
[SerializeField] GameObject[] liveToReapply; // Existing objects to re-apply
public async void OnResetPressed()
{
// 1) Respawn destroyed props from the newest save
await SaveManager.Instance.RestoreSinglePrefabsFromMostRecentSlotAsync(propsToRespawn);
// 2) Re-apply saved state to existing objects from the newest save
await SaveManager.Instance.RestoreSingleGameObjectsFromMostRecentSlotAsync(liveToReapply);
}
}
Troubleshooting
“Nothing happens when I call RestoreDestroyedGameObject.” Check that the prefab is known to Crystal Save (SaveablePrefab on the asset) and the destroyed instance’s ID actually exists in the save.
“It respawns, but looks default.” The object was not tracked when it was destroyed, so only the prefab could be respawned. Add the appropriate Remember components and save again.
“Restore by ID can’t find my object.” Confirm the UniqueID string. You can reveal it in the Inspector on the UniqueID component (Debug mode) or log it during play for your objects or click the UniqueID button in the Remember Prefab (aka SaveablePrefab) component or in case of the Remember Prefab (aka SaveablePrefab) click the CopyID button .
Quick API cheat‑sheet
Re-apply to a live object
SaveManager.Instance.RestoreSingleGameObject(GameObject target, int slot);
SaveManager.Instance.RestoreSingleGameObject(string uniqueID, int slot);
SaveManager.Instance.RestoreSingleGameObject(GameObject target); // from current SaveData
Destroyed → respawn
SaveManager.Instance.RestoreDestroyedGameObject(string uniqueID);
SaveManager.Instance.RestoreAllDestroyedGameObjects();
SaveManager.Instance.IsGameObjectDestroyed(string uniqueID)
From most recent slot (helpers)
await SaveManager.Instance.RestoreSinglePrefabsFromMostRecentSlotAsync(string[] ids);
await SaveManager.Instance.RestoreSingleGameObjectsFromMostRecentSlotAsync(GameObject[] objects);
Last updated