Page 1 of 1
PersistentData component scripting
Posted: Sat Nov 28, 2015 12:03 pm
by mandi
Hello Tony,
could you share a few examples on how to write custom Persisten Data components? Or at least where to find more information about it? I am about to write my own Persistent Data Transform (keeps not only position and rotation, but also scale), as well as several PD components which would hold specific values / properties.
Best!
Re: PersistentData component scripting
Posted: Sat Nov 28, 2015 12:45 pm
by mandi
Hello,
I've also noticed two things:
When I restart a game after saving it, and make a load, the track window does not display the last active quest.
Also, the dialog I triggered before (which was marked as trigger once, meaning Conversation Trigger was destroyed afterward; no Lua Variables here), was triggered again after loading the save - do I need to add Persistent Destructible to that Conversation Trigger?
Thank you in advance
Best!
PS. I am using DS 1.5.5.1
Re: PersistentData component scripting
Posted: Sat Nov 28, 2015 1:09 pm
by Tony Li
Hi,
mandi wrote:When I restart a game after saving it, and make a load, the track window does not display the last active quest.
You may need to call
DialogueManager.SendUpdateTracker() after loading.
mandi wrote:Also, the dialog I triggered before (which was marked as trigger once, meaning Conversation Trigger was destroyed afterward; no Lua Variables here), was triggered again after loading the save - do I need to add Persistent Destructible to that Conversation Trigger?
The "Only Once" checkbox isn't tied to the Save System. Persistent Destructible only tracks if the entire GameObject is destroyed. Since the "Only Once" checkbox only removes the Conversation Trigger, Persistent Destructible won't track it.
It would be better to use your own persistent data component or put the Conversation Trigger on a separate GameObject and use Persistent Active Data to set it active/inactive based on some condition such as a variable that you set in the conversation.
For your custom persistent transform component, you can find PersistentPositionData.cs in the SourceCode.unitypackage file. (Import it into a temporary project to prevent the scripts from conflicting with the DLL version.) It's in Assets/Dialogue System/Scripts/Supplemental/Save System/. You could use this as a starter for your component that also tracks scale. Or you could just use the template in Scripts/Templates without having to import the source code.
Most persistent data components use
DialogueLua.SetVariable() in OnRecordPersistentData to save information. They use
DialogueLua.GetVariable() to retrieve information in OnApplyPersistentData. The PersistentPositionData.cs script is a little different; it stores position data in Lua's Actor[] table instead of the Variable[] table.
Re: PersistentData component scripting
Posted: Sat Nov 28, 2015 4:36 pm
by mandi
Tony,
thank you very much for this very useful answer!
If I understand the save system correctly (please correct me if I'm wrong), my options to ensure conversation flow is saved properly is to:
1. Put Conversation Triggers on separate GOs, and disable them using Persistent Active Data, or
2. Use my own PD component.
All the above in case I don't use Lua variables to initiate conversation. But then, if I use them, do I need still to attach a PD component (be it Persistent Active Data or my own) to each and every conversation trigger? I mean, what is the best, most automated practice to save conversations?
Best!
Re: PersistentData component scripting
Posted: Sat Nov 28, 2015 11:49 pm
by Tony Li
I think the best, easiest way is to use a Lua variable. Then check that Lua variable in the Conversation Trigger's Condition section. This way you don't need to use any persistent data components at all because the Lua variables are automatically saved.
Re: PersistentData component scripting
Posted: Sun Nov 29, 2015 10:51 am
by mandi
Tony,
Perfect! Thank you very much.
Best,
Artur