Page 1 of 1

Quest active state

Posted: Sat Aug 26, 2023 5:30 am
by StrujaMojaKuja
Hello, I have an issue where I have an enemy spawner that I want only active if the quest is active. But on the next load the quest is always set to unassigned, meaning these conditions are not true. Does it have an easy fix?

Re: Quest active state

Posted: Sat Aug 26, 2023 8:45 am
by Tony Li
Hi,

One solution is to set up the save system. This will let you save the game, including quest states.

Then you can either:
  • Add a Dialogue System Trigger to the scene and set its Trigger to OnSaveDataApplied. Set the Conditions > Quest Conditions to require that the quest state is active. Set Actions > OnExecute() UnityEvent to activate the spawner.
  • Or, instead of a Dialogue System Trigger, set up an Active Saver component on an active GameObject. Assign a unique key value of your choice (e.g., "enemySpawner001") and assign the spawner to the Target field. This will save the spawner's active/inactive state.

Re: Quest active state

Posted: Sat Aug 26, 2023 11:01 am
by StrujaMojaKuja
I am not using save system, I am only using 2 lines of code you provided in the different forum post to save the quests. The solution you gave did not really work for me, the first one is already set up in the scene and the quest state is still set to unassigned, the second solution one did not save the state of the object, it is still inactive after loading the game :(

Re: Quest active state

Posted: Sat Aug 26, 2023 11:08 am
by Tony Li
Are you using "PersistentDataManager.GetSaveData()" and "PersistentDataManager.ApplySaveData()" to save and restore the quest states? If so, make sure that's working first. In other words, after calling PersistentDataManager.ApplySaveData(), confirm that the quest states are correct.

If so, then after restoring the quest states with PersistentDataManager.ApplySaveData() you'll need to check the quest state and activate or deactivate the spawner accordingly. Another alternative is to add a PersistentActiveData component to an active GameObject in the scene. Assign the spawner to the Target field, and set the Condition to require that the quest is active.

Or use the save system, which will take care of this by using an ActiveSaver.

Re: Quest active state

Posted: Sat Aug 26, 2023 11:11 am
by StrujaMojaKuja
I am only saving quests in a string with these lines:
string s = PixelCrushers.DialogueSystem.PersistentDataManager.GetSaveData();
PixelCrushers.DialogueSystem.PersistentDataManager.ApplySaveData(s);
I am pretty sure that this does not save quest states, right?

Re: Quest active state

Posted: Sat Aug 26, 2023 11:33 am
by Tony Li
That does save quest states and DS variable values.

The first line (PersistentDataManager.GetSaveData) returns a string containing the saved quest states and variable values.

The second line (PersistentDataManager.ApplySaveData) accepts a string and uses it to restore quest states and variable values.

Re: Quest active state

Posted: Sat Aug 26, 2023 12:29 pm
by StrujaMojaKuja
Thank you, using Persistent Active Data script worked! Thank you for your time and for making the best asset on the store! :D

Re: Quest active state

Posted: Sat Aug 26, 2023 1:43 pm
by Tony Li
Thanks! Glad to help.