I removed Awake() and OnEnable(), but the save still doesn't work.Tony Li wrote: ↑Thu Dec 22, 2022 11:38 am 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?
Code: Select all
using Opsive.Shared.Events;
using Opsive.UltimateInventorySystem.Core;
using PixelCrushers.QuestMachine;
using System.Collections;
using UnityEngine;
[System.Serializable]
public class ActiveEquippedItemQuestCondition : QuestCondition
{
[SerializeField] private ItemDefinition activeEquippedItemDefinition = default;
private void OnEquipItemComplete(Opsive.UltimateCharacterController.Items.Item item, int arg2)
{
if (quest.GetState() == QuestState.Successful)// || questNode.GetState() == QuestNodeState.Inactive)
{
return;
}
if (item.ItemDefinition == activeEquippedItemDefinition)
{
QuestMachineConfiguration.instance.StartCoroutine(StateSetTrue());
}
}
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.SetConditionChecking(false);
child.SetState(QuestNodeState.Inactive);
}
questNode.ResetConditions();
questNode.SetState(QuestNodeState.Active);
}
private IEnumerator StateSetTrue()
{
yield return null;
SetTrue();
}
public override string GetEditorName()
{
return "Check Active Equipped Item: " + activeEquippedItemDefinition;
}
public override void StartChecking(System.Action trueAction)
{
if (GlobalCache.Instance != null && GlobalCache.Instance.HumanCharacter != null)
{
EventHandler.RegisterEvent<Opsive.UltimateCharacterController.Items.Item, int>(GlobalCache.Instance.HumanCharacter, "OnInventoryEquipItem", OnEquipItemComplete);
EventHandler.RegisterEvent<Opsive.UltimateCharacterController.Items.Item, int>(GlobalCache.Instance.HumanCharacter, "OnAbilityUnequipItemComplete", OnUnequipItemComplete);
EventHandler.RegisterEvent<Opsive.UltimateCharacterController.Items.Item, int>(GlobalCache.Instance.HumanCharacter, "OnInventoryRemoveItem", OnInventoryRemoveItem);
}
base.StartChecking(trueAction);
if (IsTrue()) SetTrue();
quest.stateChanged += OnQuestStateChanged;
}
private bool IsTrue()
{
var activeEquippedItemInSlot0 = GlobalCache.Instance.CharacterInventoryBridge.GetActiveInventoryItem(0);
if (activeEquippedItemInSlot0 != null)
{
if (activeEquippedItemInSlot0.GetItemDefinition() == activeEquippedItemDefinition)
{
return true;
}
}
return false;
}
private void OnQuestStateChanged(Quest quest)
{
if (quest.GetState() == QuestState.Successful)
{
if (GlobalCache.Instance != null && GlobalCache.Instance.HumanCharacter != null)
{
EventHandler.UnregisterEvent<Opsive.UltimateCharacterController.Items.Item, int>(GlobalCache.Instance.HumanCharacter, "OnInventoryEquipItem", OnEquipItemComplete);
EventHandler.UnregisterEvent<Opsive.UltimateCharacterController.Items.Item, int>(GlobalCache.Instance.HumanCharacter, "OnAbilityUnequipItemComplete", OnUnequipItemComplete);
EventHandler.UnregisterEvent<Opsive.UltimateCharacterController.Items.Item, int>(GlobalCache.Instance.HumanCharacter, "OnInventoryRemoveItem", OnInventoryRemoveItem);
}
}
}
}