SavedRef¶
A cross-reference to another object inside a save state, encoded into something stable enough to survive a save and reload.
Namespace: Jungle.State
Inherits: plain [Serializable] class
Overview¶
A save state often needs to say "this slot held that object". A raw Unity reference cannot survive a save, because the object it points at will be a different instance next session, or will not exist yet at the moment the state is read back.
SavedRef holds the live reference while the game runs, and is encoded on save into one of two stable forms:
- Permanent — the object is one the scene always has, identified by a Key name.
- Pooled — the object came out of a creator, identified by the creator's Key name plus its index in that creator's instances.
On restore, the same registry turns the encoded form back into a live reference. As an author you only ever call Set and Get<T>; the encoding and decoding are driven by the SceneState.
Runtime API¶
| Member | Description |
|---|---|
Set(Object) |
Store the live reference. |
Get<T>() |
Read the live reference back, typed. |
Runtime |
The live reference, untyped. |
IsEmpty |
True when nothing was encoded. |
IsPermanent |
True when it encoded to a permanent Key name. |
IsPooled |
True when it encoded to a creator Key name plus an instance index. |
Encoding¶
The registry (ISavedRefRegistry) calls EncodeAsPermanent, EncodeAsPooled or EncodeAsEmpty during save, and resolves the result during restore. Do not call these from state-authoring code.
See Also¶
- SceneState
- ObjectStateHolder
- Save & Restore
- Key