When “Quit to Main Menu” is used in Dinkum, it reloads the main scene. This can cause issues if you've created game objects that you want to be persistent. So, in order to avoid issues, use the following guidelines.
- If your object is part of the player's world…
- It does not need to be persistent.
- It's best to create/destroy these as necessary when the player's save slot is loaded.
- If your object is part of the user interface or always exists in all save slots…
- If your object has no parent object
- After creating the object, use
DontDestroyOnLoad(yourObject);
- This will ensure it is not destroyed when loading back into the main menu.
- If your object does have a parent object…
- Put all code relevant to the creation of the object and its setup into its own method. (In this example, we'll call it
CreateObject
)
- After initializing your plugin, use
TRTools.sceneSetupEvent += CreateObject;
- Your creation method will now be called automatically when loading into the main menu scene so the object will be recreated as necessary.