Page 1 of 1

Problems using "Messages" to notify player of "New Quest" and "Completed Quest"

Posted: Wed Mar 06, 2024 12:40 pm
by mroshaw
Hi!

I'm trying to use "Messages" to let the player know when a new quest is received, and when a quest is completed.

I have a "Notification Manager" component that has public methods that show a message on screen and plays a sound. Alongside that component, I have a "Message Events" component. It is set up to listen for two messages:
  • Sender: Any
  • Target: Any
  • Message: Notification Manager
  • Parameter: New Quest
  • Event: <Notification Manager New Quest Method>
and:
  • Sender: Any
  • Target: Any
  • Message: Notification Manager
  • Parameter: Quest Success
  • Event: <Notification Manager Quest Succeed Method>
In my Quest, I've configured as follows:

On the "Start" state, in its "Active" state, I have a Message action:
  • Sender: Quest Giver
  • Target: Any
  • Message: Notification Manager
  • Parameter: New Quest
In the "Success" state, in its "Active" state, I have a message action:
  • Sender: Quest Giver
  • Target: Any
  • Message: Notification Manager
  • Parameter: Quest Success
When I play my game, I see the following:
  • The "New Quest" event is triggered twice, when my character accepts the Quest.
  • The "Quest Success" event is not triggered at all, when my character completes the quest.
Am I using the messaging system and Quest "states" correctly?

Many thanks!

Re: Problems using "Messages" to notify player of "New Quest" and "Completed Quest"

Posted: Wed Mar 06, 2024 3:39 pm
by Tony Li
Hi,

First, why not use the existing QuestMachineMessages.QuestStateChangedMessage like i in the example code in How To: Respond To Quest State Changes in Script?

If you don't want to do that, temporarily tick the Quest Machine GameObject's Debug Settings > Debug and Debug Message System checkboxes. This will log a lot of info to the Console. You should be able to see when/if it sends those messages.

Re: Problems using "Messages" to notify player of "New Quest" and "Completed Quest"

Posted: Wed Mar 06, 2024 4:11 pm
by mroshaw
Thanks Tony!

I moved the action from the "Active" state to the "True" state, and it's working as expected!

Re: Problems using "Messages" to notify player of "New Quest" and "Completed Quest"

Posted: Wed Mar 06, 2024 8:08 pm
by Tony Li
Hi,

Great! Thanks for the update.

Re: Problems using "Messages" to notify player of "New Quest" and "Completed Quest"

Posted: Thu Mar 07, 2024 11:42 am
by mroshaw
Hi Tony!

I've looked at your first suggestion, using QuestStateChangedMessage, and it is a far superior solution! So I've scrapped all my rubbish code, and implemented your recommendation. Much better, and much more flexible!

Thanks again!!

Re: Problems using "Messages" to notify player of "New Quest" and "Completed Quest"

Posted: Thu Mar 07, 2024 11:44 am
by Tony Li
Glad to help!

Re: Problems using "Messages" to notify player of "New Quest" and "Completed Quest"

Posted: Thu Mar 07, 2024 12:40 pm
by mroshaw
Can I be really cheeky and ask one more question, Tony?

Is there a way I can use QuestStateChangedMessage to detect a "quest has been updated" kind of event?

I'm thinking:

"You have a new quest!" - when Quest state goes to Active.
"Quest completed!" - when Quest state goes to Successful.
"Current quest updated!" - when a quest moves to a new node, except for the first node after "Start" and the "Success" node - since those will already trigger a Quest state change.

Does that make sense?

Re: Problems using "Messages" to notify player of "New Quest" and "Completed Quest"

Posted: Thu Mar 07, 2024 3:27 pm
by Tony Li
You can use the same QuestMachineMessages.QuestStateChangedMessage.

If messageArgs.values[0] is null, the main quest state has changed, and (QuestState)values[1] is the main quest's state.

If messageArgs.values[0] is not null, a quest node's state has changed, and (StringField)values[0] is the ID of the quest node and (QuestNodeState)values[1] is the node's new state.

Re: Problems using "Messages" to notify player of "New Quest" and "Completed Quest"

Posted: Thu Mar 07, 2024 4:07 pm
by mroshaw
That's amazing, thank you!!!