Saving Variable Values
1_ScriptableVariable
Last updated
1_ScriptableVariable
Last updated
If you enter play mode, and press the button “End Tutorial”, you will see that the Tutorial object will disable itself.
Now exit play mode and play again. You can see that the changes have persisted. It’s because the example_bool_tutorialCompleted variable state has been saved to Player Prefs. To enable saving on your variable, select the variable and enable the property “Saved”. All scriptable variables available in the package can be saved to Player Prefs with a single click. (Except the GameObjectVariable).
When loaded for the first time, the variable will be set to the Default Value.
The key used for Player Prefs is the Save Guid of the ScriptableVariable. This Guid is generated using the path of the asset. If Auto is selected, the Guid is generated automatically. If you change it to Manual, you can override the Guid.
You can use the fact that a variable has been saved in combination with a Binding script. If you select the Tutorial in the scene, you can see that its component BindComparisonToUnityEvent will disable the object if the condition is true. Bindings are explained in the next scene.
The player position is also saved, check the PositionSaver.cs on the prefab_player in the scene.
Saving variables like this is useful for things like level index, player score, coins, tutorials completed, etc. For a more complex and bigger save system, please check the 5_ScriptableSave_Example_Scene and its documentation.
If you want to clear the variables save (deleting all Player Prefs), use the shortcut (CTRL+Shift+D) or the menu item: