[SOLVED] Message System Random Error

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
KingCeryn
Posts: 70
Joined: Sun Aug 23, 2020 5:12 pm

[SOLVED] Message System Random Error

Post by KingCeryn »

Hey again, so I solved my Quest issues a long time ago and havent touched ANYTHING related to the pixelcrushers scripts in several weeks, but today I started getting this error and I can't figure out whats causing it.

I'm still using Invector, and this quest specifically is a simple "Get vItem" fetch quest, and it was working weeks ago. However, now when i go get the item, instead of switching to the next node, it kicks out this error in the MessageSystem.

per my last few threads, I had these "QuestNodeListener" scripts written that use the MessageSystem to check when Nodes are active, to switch some UI stuff, and they all were working flawlessly with your help. But now this error is happening, and i cannot figure out why. I've been looking at everything I changed recently, and still nothing seems to be causing it. Nothing's changed in the scripts or prefabs in forever, so anything you might notice would be super helpful.

Here's the script itself that was listening, It was working fine last i checked weeks ago:

EDIT: Looks like this only happens to some of my quests, but nothing seems to be different between the ones that work and ones that dont- both have the same requirements, i.e. "Get vItem". But some work and others give that error

Code: Select all

public class QuestNodeListener : MonoBehaviour, IMessageHandler
{
    public StringField requiredQuestID;
    public StringField requiredQuestNodeID;
    [Space]
    public bool NodeStateActive;
    [Space]
    public UnityEvent OnNodeActive;
    public UnityEvent OnNodeInactive;



    void Start()
    {

    }

    void OnEnable()
    {
        MessageSystem.AddListener(this, QuestMachineMessages.QuestStateChangedMessage, requiredQuestID);
        SceneManager.sceneLoaded += OnSceneLoaded;
    }

    void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
        CheckIfNodeIsActive();
    }

    void OnDisable()
    {
        MessageSystem.RemoveListener(this);
    }

    public void OnMessage(MessageArgs messageArgs)
    {

        // "Quest State Changed" is sent when a quest state or quest node state changes. 
        // - Parameter: Quest ID. 
        // - Value 0: [StringField] Quest node ID, or null for main quest state.
        // - Value 1: [QuestState] / [QuestNodeState] New state.
        if (messageArgs.values[0] == null)
        {
            // If value 0 is null, this is the main quest state so just exit:
            return;
        }
        else
        {
            string questID = messageArgs.parameter;
            StringField questNodeID = (StringField)messageArgs.values[0];
            QuestNodeState questNodeState = (QuestNodeState)messageArgs.values[1];

            if ((questID == requiredQuestID.value) && (questNodeID.value == requiredQuestNodeID.value))
            {
           
                // This is the quest node we're interested in, so set the quest pointer based on the node's current state:
                if (questNodeState == QuestNodeState.Active)
                {
                    // (Quest node is active)
                    NodeStateActive = true;

                    OnNodeActive.Invoke();
                    //Debug.Log(requiredQuestID + " is in " + requiredQuestNodeID + " Node");

                }
                else
                {
                    // (Quest node is not active)
                    NodeStateActive = false;

                    OnNodeInactive.Invoke();
                    //Debug.Log(requiredQuestID + " is out of " + requiredQuestNodeID + " Node");
                }

            }
        }
    }


    public void CheckIfNodeIsActive()
    {
        // This is the quest node we're interested in, so set the quest pointer based on the node's current state:
        if (NodeStateActive == true)
        {
            // (Quest node is active)
            OnNodeActive.Invoke();
            //Debug.Log(requiredQuestID + " is in " + requiredQuestNodeID + " Node");
        }
        
    }



}
Attachments
message system error.PNG
message system error.PNG (40.09 KiB) Viewed 748 times
Last edited by KingCeryn on Sat Feb 26, 2022 12:12 pm, edited 1 time in total.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Message System Random Error

Post by Tony Li »

Hi,

Would you please click on the error in the Console window, press Ctrl+C to copy it to the clipboard, and paste the clipboard into a reply here?
KingCeryn
Posts: 70
Joined: Sun Aug 23, 2020 5:12 pm

Re: Message System Random Error

Post by KingCeryn »

Here's the full Error Log
It happens when I pickup the vItem, so when a Quest's node changes.
And it only happens on a few quests, not others. Ive tried looking for differences, but cant find any:




Message System exception sending 'Quest State Changed'/'HealthPotionQuest' to QuestReturnToNPCNodeListener (QuestNodeListener): Object of type 'UnityEngine.Object' cannot be converted to type 'UnityEngine.Transform'.
UnityEngine.Debug:LogError (object)


PixelCrushers.MessageSystem:SendMessageWithTarget (object,object,string,string,object[]) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Message System/MessageSystem.cs:358)
PixelCrushers.MessageSystem:SendMessage (object,string,PixelCrushers.StringField,object[]) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Message System/MessageSystem.cs:454)
PixelCrushers.QuestMachine.QuestMachineMessages:QuestNodeStateChanged (object,PixelCrushers.StringField,PixelCrushers.StringField,PixelCrushers.QuestMachine.QuestNodeState) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Utility/QuestMachineMessages.cs:165)
PixelCrushers.QuestMachine.QuestNode:SetState (PixelCrushers.QuestMachine.QuestNodeState,bool) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Node/QuestNode.cs:428)
PixelCrushers.QuestMachine.QuestNode:OnParentStateChange (PixelCrushers.QuestMachine.QuestNode) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Node/QuestNode.cs:514)
PixelCrushers.QuestMachine.QuestNode:SetState (PixelCrushers.QuestMachine.QuestNodeState,bool) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Node/QuestNode.cs:431)
PixelCrushers.QuestMachine.QuestNode:OnConditionsTrue () (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Node/QuestNode.cs:501)
PixelCrushers.QuestMachine.QuestConditionSet:SetTrue () (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Condition Set/QuestConditionSet.cs:178)
PixelCrushers.QuestMachine.QuestConditionSet:OnTrueCondition () (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Condition Set/QuestConditionSet.cs:173)
PixelCrushers.QuestMachine.QuestCondition:SetTrue () (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Subasset/Quest Condition/QuestCondition.cs:63)
PixelCrushers.QuestMachine.InvectorHasItemsQuestCondition:CheckItemCount () (at Assets/Pixel Crushers/Quest Machine/Third Party Support/Invector Support/Scripts/Quest Conditions/InvectorHasItemsQuestCondition.cs:118)
PixelCrushers.QuestMachine.InvectorHasItemsQuestCondition:OnHandleItem (Invector.vItemManager.vItem) (at Assets/Pixel Crushers/Quest Machine/Third Party Support/Invector Support/Scripts/Quest Conditions/InvectorHasItemsQuestCondition.cs:90)
UnityEngine.Events.UnityEvent`1<Invector.vItemManager.vItem>:Invoke (Invector.vItemManager.vItem)
Invector.vItemManager.vItemManager:AddItem (Invector.vItemManager.ItemReference,bool,UnityEngine.Events.UnityAction`1<Invector.vItemManager.vItem>) (at Assets/Invector-3rdPersonController/ItemManager/Scripts/vItemManager.cs:878)
Invector.vItemManager.vItemManager/<CollectItemsRoutine>d__107:MoveNext () (at Assets/Invector-3rdPersonController/ItemManager/Scripts/vItemManager.cs:1782)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Message System Random Error

Post by Tony Li »

Hi,

What's the content of your QuestNodeListener script? I suspect the error is happening in there.
KingCeryn
Posts: 70
Joined: Sun Aug 23, 2020 5:12 pm

Re: Message System Random Error

Post by KingCeryn »

Hey, I posted it up above in the first post, the full script.
But the thing is it works fine on some of my other quests, using the same setup. The script just checks for QuestNodeStates, using the MessageSystem.

The error "Message System exception sending: Object of type 'UnityEngine.Object' cannot be converted to type 'UnityEngine.Transform'." Seems to be saying that it cant send the message to the Listener, when the QuestNode changes, I dont quite understand what the error is trying to say.

As in, whats the issue its having with sending the message to that specific GameObject with the QuestNodeListener script attached. It works on other quests, but not some. And it only happens when the Node changes, not when its accepted, etc.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Message System Random Error

Post by Tony Li »

Quest Machine's message system catches errors to ensure that it's able to continue even if a message listener has an error.

Thanks for reminding me that the code is in your first post. Looking at the code, I think whatever is assigned to the OnNodeActive UnityEvent is having the error.

If you temporarily turn off the error-catching, it will give you a closer location of the actual error. To do that, edit MessageSystem.cs lines 344-360. Comment out these lines (marked with //---):

Code: Select all

if (string.Equals(x.message, message) && (string.Equals(x.parameter, parameter) || string.IsNullOrEmpty(x.parameter)))
{
    //---try
    {
        if (ShouldLogReceiver(x.listener))
        {
            Debug.Log("MessageSystem.SendMessage(sender=" + sender +
                ((target == null) ? string.Empty : (" target=" + target)) +
                ": " + message + "," + parameter + ")");
        }
        x.listener.OnMessage(messageArgs);
    }
    //---catch (System.Exception e)
    //---{
    //---    Debug.LogError("Message System exception sending '" + message + "'/'" + parameter + "' to " + x.listener + ": " + e.Message);
    //---}
}
Or, if you prefer, feel free to send a reproduction project to tony (at) pixelcrushers.com along with steps to reproduce the issue.
KingCeryn
Posts: 70
Joined: Sun Aug 23, 2020 5:12 pm

Re: Message System Random Error

Post by KingCeryn »

ah, thanks so much! As usual, its always a simple thing I never expect lol-

There was in fact a missing "Transform" reference on that event that somehow got unlinked, re-adding it fixed it!

Thanks again for all your help!
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: [SOLVED] Message System Random Error

Post by Tony Li »

Happy to help. Glad you got to the bottom of it.
Post Reply