Page 1 of 1

Custom Quest Condition Not Updating HUD

Posted: Wed Oct 13, 2021 10:36 am
by cptscrimshaw
Hi Tony,

1. I've created a couple of Custom Quest Conditions that work like a charm (the template was super helpful, thanks!), but when they execute the Quest HUD isn't updated. The player's Journal and nodes are updating correctly and if I save/load the game the HUD updates. Is there a refresh I need to do on custom question conditions?

2. Unrelated (I think), is another issue I'm having with the same quest and I think I've run into this one before but don't remember what ended up fixing it. After getting part way through the quest and saving/loading, when I reload the game I get the error:
Quest Machine: Unable to restore quest: Ysabella - A Mirror to the Heart(Clone). Message: Object reference not set to an instance of an object
https://ibb.co/CHtTQbT

Oddly, the quest is still showing up in my player Journal, but the HUD isn't showing up, and if I try to move to the next node in the quest, nothing happens, which makes sense. Any idea where to start looking for the issue?

Thanks!

Re: Custom Quest Condition Not Updating HUD

Posted: Wed Oct 13, 2021 1:31 pm
by Tony Li
Hi,

For #1: All quest UIs (quest journal UI if open, and quest HUD) should refresh whenever the quest journal is notified that a quest/node state or quest counter value has changed.

Are there any errors or warnings when the custom condition causes a quest node state to change?

Have you assigned a HUD to the player's Quest Journal component? Usually this is not done. If no HUD is assigned to the Quest Journal, it will use whatever HUD is assigned to the Quest Machine GameObject.


For #2: Would you please click on the yellow warning in the Console window, press Ctrl+C to copy the details to the clipboard, and then paste them into a reply here?

Have you modified this quest between the time you saved the game and are now trying to load it?

Re: Custom Quest Condition Not Updating HUD

Posted: Wed Oct 13, 2021 2:16 pm
by cptscrimshaw
#1 - No warnings at all - and everything appears working correctly other than the HUD updating: https://ibb.co/5rQTnht

I haven't assigned the HUD to the Player's Quest Journal component, so it should be using the default one as normal.

Here's the code for my custom condition (though I'm having the same issue with a 2nd custom condition that also appears to be working fine with no warnings or errors):

Code: Select all

namespace PixelCrushers.QuestMachine
{
    public class HasRecipe : QuestCondition // Rename this class.
    {
        public StringField recipeName = new StringField();

        public override void StartChecking(System.Action trueAction)
        {
            base.StartChecking(trueAction);

            if (IsTrue())
            {
                SetTrue();
            }
            else
            {
                EventHandler.PlayerRecipeAdded += PlayerRecipeAdded;
            }
        }

        private bool IsTrue()
        {
            foreach (var recipe in Statics.player.GetComponent<CharacterCraftingData>().playerRecipes)
            {
                if (recipe.name == recipeName.text)
                {
                    return true;
                }
            }
            return false;
        }

        private void PlayerRecipeAdded(string recipe)
        {
            recipeName.text = recipe;

            if (IsTrue())
            {
                SetTrue();
            }
        }

        public override void StopChecking()
        {
            base.StopChecking();
            EventHandler.PlayerRecipeAdded -= PlayerRecipeAdded;
        }
    }
}
#2 - Here is the console output:
Quest Machine: Unable to restore quest: Ysabella - A Mirror to the Heart(Clone). Message: Object reference not set to an instance of an object
UnityEngine.Debug:LogWarning (object,UnityEngine.Object)
PixelCrushers.QuestMachine.QuestListContainer:ApplyData (string) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest MonoBehaviours/Quest List/QuestListContainer.cs:461)
PixelCrushers.QuestMachine.QuestJournal:ApplyData (string) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest MonoBehaviours/Quest List/QuestJournal.cs:208)
PixelCrushers.SaveSystem:ApplySavedGameData (PixelCrushers.SavedGameData) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/SaveSystem.cs:654)
PixelCrushers.SaveSystem/<LoadSceneCoroutine>d__107:MoveNext () (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/SaveSystem.cs:765)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

This happens after running my second custom function on the "Research Alchemic Extraction" node in the quest (code below) and after saving and loading. I'm not touching the quest asset at all between save and load.

Code: Select all

namespace PixelCrushers.QuestMachine
{
    public class LearnedTech : QuestCondition // Rename this class.
    {
        public StringField techName = new StringField();

        public override void StartChecking(System.Action trueAction)
        {
            base.StartChecking(trueAction);
            
            if (IsTrue())
            {
                SetTrue();
            }
            else
            {
                EventHandler.LearnedTechnology += LearnedTechnology;
            }
        }

        private bool IsTrue()
        {
            TechDatabase techDatabase = Statics.techDatabase;

            foreach (var techCategory in techDatabase.techCategories)
            {
                foreach (var techGroup in techCategory)
                {
                    foreach (var technology in techGroup)
                    {
                        if (technology.techName == techName.text)
                        {
                            if (technology.availabilityState == Technology.AvailabilityState.Learned)
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }

        private void LearnedTechnology(string tech)
        {
            Debug.Log(tech);
            techName.text = tech;

            if (IsTrue())
            {
                SetTrue();
            }
        }

        public override void StopChecking()
        {
            base.StopChecking();
            EventHandler.LearnedTechnology -= LearnedTechnology;
        }
    }
}
One other thing I noticed with the Quest Machine Debugger on is when I load my game, I get a lot of warnings that I don't get otherwise (maybe this is normal?): https://ibb.co/GdHTvCm

Re: Custom Quest Condition Not Updating HUD

Posted: Wed Oct 13, 2021 2:48 pm
by Tony Li
Hi,

For #1: You could either send a reproduction project to tony (at) pixelcrushers.com, or -- if you just want it to work -- try adding this line to your IsTrue() method:

Code: Select all

        private bool IsTrue()
        {
            foreach (var recipe in Statics.player.GetComponent<CharacterCraftingData>().playerRecipes)
            {
                if (recipe.name == recipeName.text)
                {
                    QuestMachineMessages.RefreshUIs(this); //<-- ADD THIS LINE.
                    return true;
                }
            }
(Edit: Fixed typo.)

For #2: Have you assigned your quests (Magic Chicken Stock, etc.) to the quest database asset that's assigned to the Quest Machine GameObject?

What is line 208 in your copy of Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest MonoBehaviours/Quest List/QuestJournal.cs?

Re: Custom Quest Condition Not Updating HUD

Posted: Wed Oct 13, 2021 4:46 pm
by cptscrimshaw
#1 - Adding in that line didn't seem to solve the issue. I'll put together a reproduction project and send it along, thanks! Btw, if you want to update your post, it should be QuestMachineMessages.RefreshUIs(this); You were missing the "s" on Messages.

#2 - Line 208 is:

Code: Select all

base.ApplyData(data);
I believe I'm on the previous version of Quest Machine if that makes a difference.

Re: Custom Quest Condition Not Updating HUD

Posted: Wed Oct 13, 2021 4:51 pm
by Tony Li
Thanks. I'll keep an eye out for your reproduction project.

Re: Custom Quest Condition Not Updating HUD

Posted: Wed Oct 13, 2021 10:28 pm
by Tony Li
Thanks for the reproduction project.

The quest HUD is getting the message to update its display. But, because it's inactive while the inventory window is open, it doesn't update itself. Two options:

1. Instead of deactivating the HUD GameObject, disable its Canvas component. When you close the inventory, re-enable the Canvas.

2. Or, right after you close the inventory, call QuestMachineMessages.RefreshUIs(this) in C# to tell the HUD to refresh its display.