int familyOrder = DialogueLua.GetVariable(LuaConstants.CemeteryWrothFamilyOrder).asInt; --> returns -1
familyOrder will be set to its original value instead of the value from SetVariable. I just want to make sure I'm not expecting cross-scene persistence when that's not a thing. I'm sure it is, I just wanted to sanity check.
On your Dialogue Manager, are the Don't Destroy On Load and Allow Only One Instance checkboxes ticked? (The default is for them to be ticked.)
If not, you'll need to save and load. If you're using the save system, add a Dialogue System Saver component to the Dialogue Manager, and change scenes using SaveSystem.LoadScene(). If you're not using the save system, use PersistentDataManager.GetSaveData() and ApplySaveData():
I've got my Dialogue Manager setup with:
- Don't Destroy On Load
- Allow Only One Instance
- Dialogue System Saver
I'm using SaveSystem.LoadScene() to change scenes.
I did some more testing and the behavior is actually stranger than I first thought. The variable is dropped two frames after after when it's set. I'm printing it out in update and after two lookups where it IS the correct value, it goes back to the uninitialized state.
Yes. This allows components that initialize in Start() to initialize themselves before the save system applies their saved states. You can reduce the number of frames (even down to zero) by inspect the Save System component and setting Frames To Wait Before Apply Data.
Exactly. If you want to initialize based on Dialogue System internal data (variables, quests, etc.), you could always make a subclass of DialogueSystemSaver and override the ApplyData() method: