Clear LUA Environment. This part should be safe since we saved the AC game first correct?
Yup, your Lua is safe if you save the AC game first. That's a good order of operations. You might not need to destroy the Dialogue Manager manually (see below).
Additionally each one of our scenes has a Dialogue Manager GameObject in it by default. Would you consider this a good approach so that if we accidentally forget to initialize it will still be there? Presumably if there are two DS instances DS destroys the other?
The Dialogue Manager (actually the Dialogue System Controller component on it) has two relevant checkboxes:
- Dont Destroy On Load
- Allow Only One Instance
If
Dont Destroy On Load is ticked, the Dialogue Manager will stick around when you change scenes, including when you switch to your minigame scene. In this case, you'll need to manually destroy it. But if the checkbox is unticked, Unity will automatically destroy the Dialogue Manager GameObject when switching scenes, like any regular GameObject in the scene.
If
Allow Only One Instance is ticked, when the Dialogue Manager starts, it will look for an existing Dialogue Manager. If it finds an existing Dialogue Manager, it will destroy itself, leaving only the original Dialogue Manager.
If the Dialogue Manager sticks around (either because the checkbox is unticked or because there's no pre-existing Dialogue Manager), the Dialogue Manager will clear the Lua environment and populate it with its
Initial Database info. You can repopulate it with the runtime values by grabbing the AC variable that holds the Dialogue System saved data, and run it through Lua.Run(). (The AC variable actually contains Lua code to recreate the saved Lua environment.) This is why it might be easiest to keep the Dialogue Manager around. You don't need to fiddle with repopulating Lua.
A lot of devs tick both checkboxes (which is the default) and still add a Dialogue Manager to each scene. This lets them test the Dialogue System in that scene without having to come from another scene that has the Dialogue Manager. But if you are coming from another scene with an existing Dialogue Manager, that Dialogue Manager will continue to live and destroy the new scene's Dialogue Manager, keeping all your Lua data happily intact.