Page 1 of 2
Unable to save/load data
Posted: Thu Dec 15, 2022 10:03 am
by EVG
Good afternoon, I use Quest Machine and Easy Save 3, I complete a quest, I try to save the data, then I load the data, but nothing happens, the quest just becomes active, not completed. What am I doing wrong?
Save code:
Code: Select all
string saveData = SaveSystem.Serialize(SaveSystem.RecordSavedGameData());
ES3.Save("Quests", saveData, SaveDataFileName, settings);
Load code:
Code: Select all
if (ES3.KeyExists("Quests", SaveDataFileName, settings))
{
string LoadData = ES3.Load<string>("Quests", SaveDataFileName, settings);
SaveSystem.ApplySavedGameData(SaveSystem.Deserialize<SavedGameData>(LoadData));
}
Re: Unable to save/load data
Posted: Thu Dec 15, 2022 6:32 pm
by Tony Li
Hi,
Make sure your player’s Quest Journal component > Save Settings > Remember Completed Quests checkbox is ticked, and that a unique Save Key is assigned.
Re: Unable to save/load data
Posted: Fri Dec 16, 2022 5:40 am
by EVG
Tony Li wrote: ↑Thu Dec 15, 2022 6:32 pm
Hi,
Make sure your player’s Quest Journal component > Save Settings > Remember Completed Quests checkbox is ticked, and that a unique Save Key is assigned.
Tried different settings, did not help
Re: Unable to save/load data
Posted: Fri Dec 16, 2022 10:38 am
by Tony Li
Hi,
What version of Quest Machine are you using?
Are there any errors or warnings in the Console?
If it’s not saving at all, the quest should not appear in the Quest Journal. (Unless you talk to the NPC and pick it up again.)
At what point in the loading process are you calling your ES loading code? If it’s in an Awake method, you may be calling it before the Quest Journal has initialized.
Re: Unable to save/load data
Posted: Fri Dec 16, 2022 10:59 am
by EVG
Tony Li wrote: ↑Fri Dec 16, 2022 10:38 am
Hi,
What version of Quest Machine are you using?
Are there any errors or warnings in the Console?
If it’s not saving at all, the quest should not appear in the Quest Journal. (Unless you talk to the NPC and pick it up again.)
At what point in the loading process are you calling your ES loading code? If it’s in an Awake method, you may be calling it before the Quest Journal has initialized.
I am using the latest version 1.2.32.2. I save manually after completing the quest, and load it about half a second after the Start method. There are no errors or warnings. All my quests have Current State = Active
Re: Unable to save/load data
Posted: Tue Dec 20, 2022 4:08 pm
by EVG
Any help
Re: Unable to save/load data
Posted: Tue Dec 20, 2022 4:57 pm
by Tony Li
I'm sorry; I must have missed the forum notification.
You could try ticking the Debug checkbox on the SaveSystem component and PlayerPrefsSavedGameDataStorer component. Then play in the editor and reproduce the issue. Review the Console logs. It will show unformatted JSON. You should be able to find the QuestJournal component's Key value. Make sure it lists the quests. If these are human-authored quests (made in the Quest Editor), the actual quest data won't be readable since it will be in a compressed format.
If that doesn't help, please send a
reproduction project to tony (at) pixelcrushers.com.
Re: Unable to save/load data
Posted: Thu Dec 22, 2022 6:18 am
by EVG
Tony Li wrote: ↑Tue Dec 20, 2022 4:57 pm
I'm sorry; I must have missed the forum notification.
You could try ticking the Debug checkbox on the SaveSystem component and PlayerPrefsSavedGameDataStorer component. Then play in the editor and reproduce the issue. Review the Console logs. It will show unformatted JSON. You should be able to find the QuestJournal component's Key value. Make sure it lists the quests. If these are human-authored quests (made in the Quest Editor), the actual quest data won't be readable since it will be in a compressed format.
If that doesn't help, please send a
reproduction project to tony (at) pixelcrushers.com.
It's strange, but in the new test project, saving worked, I will continue to try to find out the reason. And here's the question: Is it possible that the problem with saving is due to my own conditional scripts?
I also found a problem with the QuestControl script, when added to an object, it is not displayed in the inspector and the console gives errors:
Code: Select all
ArgumentException: You can only call GUI functions from inside OnGUI.
UnityEngine.GUIUtility.CheckOnGUI () (at <3859f4a893614f508581f22c26c521c2>:0)
UnityEngine.GUI.get_skin () (at <3859f4a893614f508581f22c26c521c2>:0)
PixelCrushers.HelpBoxAttributeDrawer.GetHeight () (at Assets/Plugins/Pixel Crushers/Common/Scripts/Editor/Misc/HelpBoxAttributeDrawer.cs:18)
UnityEditor.UIElements.PropertyField.ResetDecoratorDrawers (UnityEditor.PropertyHandler handler) (at <f7044ab663d344a2badf1160e57d1c1d>:0)
UnityEditor.UIElements.PropertyField.Reset (UnityEditor.SerializedProperty newProperty) (at <f7044ab663d344a2badf1160e57d1c1d>:0)
UnityEditor.UIElements.PropertyField.Reset (UnityEditor.UIElements.SerializedPropertyBindEvent evt) (at <f7044ab663d344a2badf1160e57d1c1d>:0)
UnityEditor.UIElements.PropertyField.ExecuteDefaultActionAtTarget (UnityEngine.UIElements.EventBase evt) (at <f7044ab663d344a2badf1160e57d1c1d>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <469e18a818964f39910fa06bef052d82>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtCurrentTargetAndPhase (UnityEngine.UIElements.EventBase evt) (at <469e18a818964f39910fa06bef052d82>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase evt) (at <469e18a818964f39910fa06bef052d82>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetAndDefaultPhase (UnityEngine.UIElements.EventBase evt) (at <469e18a818964f39910fa06bef052d82>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.SendBindingEvent[TEventType] (TEventType evt, UnityEngine.UIElements.VisualElement target) (at <5446cb99fdb34f998efe59800990e72f>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindPropertyRelative (UnityEngine.UIElements.IBindable field, UnityEditor.SerializedProperty parentProperty) (at <5446cb99fdb34f998efe59800990e72f>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <5446cb99fdb34f998efe59800990e72f>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <5446cb99fdb34f998efe59800990e72f>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <5446cb99fdb34f998efe59800990e72f>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <5446cb99fdb34f998efe59800990e72f>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <5446cb99fdb34f998efe59800990e72f>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.ContinueBinding (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at <5446cb99fdb34f998efe59800990e72f>:0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.Bind (UnityEngine.UIElements.VisualElement element) (at <5446cb99fdb34f998efe59800990e72f>:0)
UnityEditor.UIElements.Bindings.DefaultSerializedObjectBindingImplementation.Bind (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedObject obj) (at <5446cb99fdb34f998efe59800990e72f>:0)
UnityEditor.UIElements.BindingExtensions.Bind (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedObject obj) (at <f7044ab663d344a2badf1160e57d1c1d>:0)
UnityEditor.UIElements.InspectorElement..ctor (UnityEditor.Editor editor, UnityEditor.UIElements.InspectorElement+Mode mode) (at <f7044ab663d344a2badf1160e57d1c1d>:0)
UnityEditor.UIElements.EditorElement.BuildInspectorElement () (at <f7044ab663d344a2badf1160e57d1c1d>:0)
UnityEditor.UIElements.EditorElement.CreateInspectorElement () (at <f7044ab663d344a2badf1160e57d1c1d>:0)
UnityEditor.EditorElementUpdater.CreateInspectorElementsForViewport (UnityEngine.UIElements.ScrollView viewport, UnityEngine.UIElements.VisualElement contentContainer) (at <f7044ab663d344a2badf1160e57d1c1d>:0)
UnityEditor.PropertyEditor.RebuildContentsContainers () (at <f7044ab663d344a2badf1160e57d1c1d>:0)
UnityEditor.InspectorWindow.RedrawFromNative () (at <f7044ab663d344a2badf1160e57d1c1d>:0)
I am using Unity 2022.2.1f1
Re: Unable to save/load data
Posted: Thu Dec 22, 2022 7:03 am
by EVG
As it turned out, the problem with saving is present in quests where I use my condition scripts. What is wrong in my script? I check the current active item in it.
Code: Select all
using Opsive.Shared.Events;
using Opsive.UltimateCharacterController.Integrations.UltimateInventorySystem;
using Opsive.UltimateInventorySystem.Core;
using UnityEngine;
namespace PixelCrushers.QuestMachine
{
[System.Serializable]
public class ActiveEquippedItemQuestCondition : QuestCondition
{
[SerializeField] private ItemDefinition activeEquippedItemDefinition = default;
private CharacterInventoryBridge characterInventoryBridge;
private GameObject player;
private void Awake()
{
player = GameObject.FindGameObjectWithTag("Player");
if (player != null)
{
characterInventoryBridge = player.GetComponent<CharacterInventoryBridge>();
}
}
private void OnEquipItemComplete(Opsive.UltimateCharacterController.Items.Item item, int arg2)
{
if (quest.GetState() == QuestState.Successful || questNode.GetState() == QuestNodeState.Inactive)
{
return;
}
if (item.ItemDefinition == activeEquippedItemDefinition)
{
SetTrue();
}
}
private void OnUnequipItemComplete(Opsive.UltimateCharacterController.Items.Item item, int arg2)
{
if (quest.GetState() == QuestState.Successful || questNode.GetState() == QuestNodeState.Inactive)
{
return;
}
if (item.ItemDefinition == activeEquippedItemDefinition)
{
SetNodeInactive();
}
}
private void OnInventoryRemoveItem(Opsive.UltimateCharacterController.Items.Item item, int arg2)
{
if (quest.GetState() == QuestState.Successful || questNode.GetState() == QuestNodeState.Inactive)
{
return;
}
if (item.ItemDefinition == activeEquippedItemDefinition)
{
SetNodeInactive();
}
}
private void SetNodeInactive()
{
foreach (QuestNode child in questNode.childList)
{
child.SetState(QuestNodeState.Inactive);
}
questNode.SetState(QuestNodeState.Active);
}
public override string GetEditorName()
{
return "Check Active Equipped Item: " + activeEquippedItemDefinition;
}
public override void StartChecking(System.Action trueAction)
{
base.StartChecking(trueAction);
if (IsTrue()) SetTrue();
quest.stateChanged += OnQuestStateChanged;
}
private bool IsTrue()
{
var activeEquippedItemInSlot0 = characterInventoryBridge.GetActiveInventoryItem(0);
if (activeEquippedItemInSlot0 != null)
{
if (activeEquippedItemInSlot0.GetItemDefinition() == activeEquippedItemDefinition)
{
return true;
}
}
return false;
}
private void OnEnable()
{
if (player != null)
{
EventHandler.RegisterEvent<Opsive.UltimateCharacterController.Items.Item, int>(player, "OnInventoryEquipItem", OnEquipItemComplete);
EventHandler.RegisterEvent<Opsive.UltimateCharacterController.Items.Item, int>(player, "OnAbilityUnequipItemComplete", OnUnequipItemComplete);
EventHandler.RegisterEvent<Opsive.UltimateCharacterController.Items.Item, int>(player, "OnInventoryRemoveItem", OnInventoryRemoveItem);
}
}
private void OnQuestStateChanged(Quest quest)
{
if (quest.GetState() == QuestState.Successful)
{
if (player != null)
{
EventHandler.UnregisterEvent<Opsive.UltimateCharacterController.Items.Item, int>(player, "OnInventoryEquipItem", OnEquipItemComplete);
EventHandler.UnregisterEvent<Opsive.UltimateCharacterController.Items.Item, int>(player, "OnAbilityUnequipItemComplete", OnUnequipItemComplete);
EventHandler.UnregisterEvent<Opsive.UltimateCharacterController.Items.Item, int>(player, "OnInventoryRemoveItem", OnInventoryRemoveItem);
}
}
}
}
}
Re: Unable to save/load data
Posted: Thu Dec 22, 2022 11:38 am
by Tony Li
Hi,
Regarding the QuestControl error message, this is a bug in Unity 2022. This patch has a temporary fix:
PixelCrushers_HelpAttributePatch_2022-12-22.unitypackage
Regarding your custom quest condition, QuestCondition is not a MonoBehaviour. You can't count on Awake() or OnEnable(). Can you rewrite it to eliminate those methods?