Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views6 pages

Preserving Scene State

The document discusses the issue of game items reappearing when switching between scenes due to the instantiation of gameobjects each time a scene is loaded. It proposes the implementation of a 'SaveLoadManager' to track and maintain the state of scenes, specifically the items collected by the player. This manager will utilize an ISaveable interface to allow gameobjects to register and manage their save and restore functionalities for scene data.

Uploaded by

pytest0810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Preserving Scene State

The document discusses the issue of game items reappearing when switching between scenes due to the instantiation of gameobjects each time a scene is loaded. It proposes the implementation of a 'SaveLoadManager' to track and maintain the state of scenes, specifically the items collected by the player. This manager will utilize an ISaveable interface to allow gameobjects to register and manage their save and restore functionalities for scene data.

Uploaded by

pytest0810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Preserving Scene State

Why Do Items Re-Appear When I Move Between Scenes?

• Each scene we have created has a number of gameobjects that get instantiated every time the scene is loaded.
• These gameobjects include the ‘Items’ that we created for the scene.
• When a scene is first loaded this is fine – all the Items get instantiated.
• Then our player walks around the scene ... collects items and adds them to his inventory ... moves to a different
scene and does the same ... moves back to the first scene and ... all the items he collected before have
reappeared!
• This isn’t an error. Every time a scene loads it instantiates all the gameobjects in the scene that were specified
at design time. By default the scene knows nothing about the items that your player character has collected.

What we need is a way of keeping track of the ‘scene state’ i.e. in this case what items
the player has collected in the scene, so when the player re-visits the scene only the items
that should be there are displayed
Preserving Scene State
We Need A Way To Maintain The ‘State’ Of Scenes

Implement a ‘SaveLoadManager’
SceneControllerManager

BeforeSceneUnloadFadeOut SaveLoadManager

Store Scene Data


BeforeSceneUnload

Restore Scene Data


AfterSceneLoad

AfterSceneLoadFadeIn
Preserving Scene State
We'll Create A Save & Load Manager

SaveLoadManager

Gameobjects That Need To Save Scene State Will


Register Themselves With The SaveLoadManager

Store Scene Data


SceneItemsManager
ISaveable
ObjectList
ISaveable Interface Restore Scene Data
ISaveableRegister
ISaveableDeregister
ISaveableStoreScene
ISaveableRestoreScene

They Will Implement The ISaveable Interface To


Define The Methods They Need To Implement
For Scene Saving (this will be extended in future
lectures to add ISaveableSave and ISaveableLoad
for game saving to file)
Preserving Scene & Game State
Gameobjects That Need To Save Extend In Future Lectures – Scene and Game Saving
Scene & Game State Will Implement
The ISaveable Interface

SceneItemsManager SaveLoadManager

Player Store Scene Data

NPC Restore Scene Data


ISaveable
ObjectList
InventoryManager Save Data To File

TimeManager Load Data From File

GridPropertiesManager
Preserving Scene State
High Level Save System

SceneControllerManager
SaveLoadManager
BeforeSceneUnloadFadeOut
Store Scene Data

BeforeSceneUnload Restore Scene Data


Game UI

Save Data To File Save Game


AfterSceneLoad

Load Data From File Load Game

AfterSceneLoadFadeIn
Preserving Scene State
Using SceneItemsManager To Store Scene Item Data
Future Save Game
Functionality
SceneItemsManager
GameSave
Dictionary
GenerateGUID string ISaveableUniqueID <string,
string GUID GameObjectSave GameObjectSave GameObjectSave>
Globally Unique Identifier

GameObjectSave
Dictionary<string, SceneSave> sceneData
Scene Name

SceneSave
Dictionary<string , List<SceneItem> listSceneItemDictionary

Identifier Name For List


SceneItem
int itemCode
Vector3Serializable Vector3Serializable position
float x, y, z string itemName

You might also like