Hi Tony,
Happy Wednesday! And happy 2025! I hope you are very well.
I have tried for a few months to figure this one myself, but no luck. I am trying to subscribe via script to the message system.
For example, I have a Quest Control component in a gameObject, and I'm using this:
questControl.SendToMessageSystem("Building:Selected");
But I cannot figure out how to receive this message. I'm trying to use Message Events, and I have looked at OnMessage, but I cannot understand how to use the MessageArgs via script. --> messageEvents.OnMessage(???);
Is there a way to do this via script? So far, I have used the Message Event component and just do everything via inspector, but the list of Messages to Listen for is quite long and I need to reduce it.
Thanks in advance!
Cheers
Nico
Message Events via script
Re: Message Events via script
Hi and Happy New Year!
There's an example script in How To: Respond To Quest State Changes in Script
It listens for the message defined in the constant QuestMachineMessages.QuestStateChangedMessage, but you can listen for any message instead, like:
Note: You could also send along a reference to the specific building that was selected, like:
and get that building reference from MessageArgs.firstValue.
There's an example script in How To: Respond To Quest State Changes in Script
It listens for the message defined in the constant QuestMachineMessages.QuestStateChangedMessage, but you can listen for any message instead, like:
Code: Select all
MessageSystem.AddListener(this, "Building", "Selected");
Code: Select all
MessageSystem.SendMessage(this, "Building", "Selected", currentBuildingSelection);
Re: Message Events via script
Thanks Toni! That was exactly how to do it!
Cheers and keep up the amazing work you do!
Cheers,
Nico
Cheers and keep up the amazing work you do!
Cheers,
Nico
Re: Message Events via script
Thanks, and glad to help!