Message System exception sending 'Quest State Changed'/'xxx' to Quest Machine

Announcements, support questions, and discussion for Quest Machine.
Post Reply
nicmar
Posts: 133
Joined: Wed Aug 21, 2019 2:39 am

Message System exception sending 'Quest State Changed'/'xxx' to Quest Machine

Post by nicmar »

Have you got any idea what the exception below means?
Previously, I started a quest by sending a message and listening to it in Autostart. It worked, but I didn't wanna have to do this for each quest, so I wanted to instead start it directly from the quest, so I changed to:

Code: Select all

questToStart.SetState(QuestState.Active);
First time it worked. But second play, I got the error below. questToStart is a reference to the MakeBurger quest asset in my project. Is that incorrect? Should I reference the instance in the quest journal, if so, how?

I don't know why this should work once and not more. Is there some event listener that weren't unsubscribed?

Thank you in advance!

Code: Select all

Message System exception sending 'Quest State Changed'/'Makeburger' to Quest Machine (BlueGoo.Quests.DisplayQuestStatusChange): Object reference not set to an instance of an object
UnityEngine.Debug:LogError(Object)
PixelCrushers.MessageSystem:SendMessageWithTarget(Object, Object, String, String, Object[]) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Message System/MessageSystem.cs:328)
PixelCrushers.MessageSystem:SendMessage(Object, String, StringField, Object[]) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Message System/MessageSystem.cs:424)
PixelCrushers.QuestMachine.QuestMachineMessages:QuestStateChanged(Object, StringField, QuestState) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Utility/QuestMachineMessages.cs:153)
PixelCrushers.QuestMachine.Quest:SetState(QuestState, Boolean) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest.cs:829)
PixelCrushers.QuestMachine.Quest:RuntimeStartup() (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest.cs:720)
PixelCrushers.QuestMachine.QuestListContainer:AddQuest(Quest) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest MonoBehaviours/Quest List/QuestListContainer.cs:183)
PixelCrushers.QuestMachine.QuestJournal:AddQuest(Quest) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest MonoBehaviours/Quest List/QuestJournal.cs:167)
PixelCrushers.QuestMachine.QuestListContainer:AddQuests(List`1) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest MonoBehaviours/Quest List/QuestListContainer.cs:170)
PixelCrushers.QuestMachine.QuestListContainer:InstantiateQuestAssets() (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest MonoBehaviours/Quest List/QuestListContainer.cs:140)
PixelCrushers.QuestMachine.QuestListContainer:Awake() (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest MonoBehaviours/Quest List/QuestListContainer.cs:124)
Working on SpaceChef - A wacky open world space western, featuring a chef with nothing to loose, after he loses everything.. ;) Follow our work on @BlueGooGames.
nicmar
Posts: 133
Joined: Wed Aug 21, 2019 2:39 am

Re: Message System exception sending 'Quest State Changed'/'xxx' to Quest Machine

Post by nicmar »

I think i got this after patching from https://www.pixelcrushers.com/phpbb/vie ... 454#p14454 so I will try and revert to see if it helps..

I'm not sure if it helped. It worked again once after removing and reapplying the patch.
And now I see that I changed the asset so the quest is always started, so I guess I'm doing that wrong.

Any ideas? :)
Working on SpaceChef - A wacky open world space western, featuring a chef with nothing to loose, after he loses everything.. ;) Follow our work on @BlueGooGames.
nicmar
Posts: 133
Joined: Wed Aug 21, 2019 2:39 am

Re: Message System exception sending 'Quest State Changed'/'xxx' to Quest Machine

Post by nicmar »

I thought I was smart, and tried:

Code: Select all

QuestMachine.GetQuestInstance(questToStart.id).SetState(QuestState.Active);
But it didn't help :(
Working on SpaceChef - A wacky open world space western, featuring a chef with nothing to loose, after he loses everything.. ;) Follow our work on @BlueGooGames.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Message System exception sending 'Quest State Changed'/'xxx' to Quest Machine

Post by Tony Li »

Hi,

You should always set the state of a quest instance, not a quest asset. A quest asset is a file in your project. A quest instance is an instantiated, in-memory copy of a quest asset.

If you have assigned a quest asset to the player's Quest Journal component, then at runtime the Quest Journal will replace the quest asset with a quest instance copy of the asset.

In your code:

Code: Select all

QuestMachine.GetQuestInstance(questToStart.id).SetState(QuestState.Active);
QuestMachine.GetQuestInstance(questToStart.id) will look for a Quest Journal in the scene. If it finds one, it will check it for a quest matching questToStart.id. If the Quest Journal doesn't have this quest, it will search all other quest instances in the scene, such as on NPCs' Quest Giver components.

Assuming QuestMachine.GetQuestInstance(questToStart.id) returns the quest from the player's Quest Journal, it should set it active.

If the quest is on an NPC Quest Giver, you should instead tell the NPC's Quest Giver component to give the quest to the player:

Code: Select all

var questGiver = npc.GetComponent<QuestGiver>();
var quest = questGiver.FindQuest(questID);
questGiver.GiveQuestToQuester(quest, playerQuestJournal);
If you only have a reference to a quest asset (a file in your project), you can still assign it to the player:

Code: Select all

// Pass a quest asset to AddQuest. Quest Journal will add an in-memory instance of it and return the instance:
var quest = questJournal.AddQuest(questAssetFile);
// Make the quest instance active:
quest.SetState(QuestState.Active);
nicmar
Posts: 133
Joined: Wed Aug 21, 2019 2:39 am

Re: Message System exception sending 'Quest State Changed'/'xxx' to Quest Machine

Post by nicmar »

I noticed now that the quest is actually setting itself to active, the inspector just didn't update to Active while watching it.
Oh, now I realized what caused the exception. I had disabled the Quest Alert UI, since it was in my way while looking at another UI element, and that causes the exception and the Alert not working.

I'm considering putting some script on Quest machine root, with all elements I want it to enable on start, but I guess quest machine still disables them on start.

Is there some workaround to this, so I can have them disabled while starting the game?

Thanks :)
Attachments
Skärmavbild 2019-10-14 kl. 18.54.04.png
Skärmavbild 2019-10-14 kl. 18.54.04.png (135.17 KiB) Viewed 3023 times
Working on SpaceChef - A wacky open world space western, featuring a chef with nothing to loose, after he loses everything.. ;) Follow our work on @BlueGooGames.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Message System exception sending 'Quest State Changed'/'xxx' to Quest Machine

Post by Tony Li »

Hi,

You can disable the Quest Alert UI's Main Panel at design time. (It's named Content Panel in the default prefab.) Then configure the OnOpen() event to call the Main Panel's GameObject.SetActive(true). In the next update, the Quest Alert UI will check if Main Panel is active when showing an alert. If not, it will automatically activate it. But having the OnOpen() event still in there won't hurt anything.
nicmar
Posts: 133
Joined: Wed Aug 21, 2019 2:39 am

Re: Message System exception sending 'Quest State Changed'/'xxx' to Quest Machine

Post by nicmar »

Ok cool, thanks!
Working on SpaceChef - A wacky open world space western, featuring a chef with nothing to loose, after he loses everything.. ;) Follow our work on @BlueGooGames.
Post Reply