Hi, am making a game where there will be multiple NPCs which are meant to simulate members of a team the Player is in. The Player will provide certain inputs that will trigger different scenarios requiring certain NPCs to provide a readback of sorts. I want the NPCs to speak one after another instead of all at once. How can i do this using Behaviour Graphs?
Hi @lesterc013!
To have agents wait for their turn to speak there are a few different approaches that you could take. One of them is to use a variable to track the current speaker, and our Conditional Guard nodes to check if the NPC in question is the current speaker, and should proceed to speak. After speaking you can add a small delay with the Wait node and then set the next speaker. Here’s an example of a simplified version of this, just to give you an idea:
Instead of simply comparing to the NPC GameObject in question you could also use add an ID for each of the NPCs, and check against that to see who has the turn to speak.
Another option could be to use event nodes, where you have the NPCs send out events when they are finished with their sequence/talking, and the NPC next in turn listens to that.
So e.g. you can send a message with the Send Event Message node when an NPC has finished talking, and have another NPC listen for that event message (with the Wait for Event Message node). When the next NPC receives a message from the event, they will start their sequence for talking, and so on. For more information about the event nodes and how to set them up you should be able to find a documentation from here.
It all really depends on the implementation that you’re going for, but let me know if you need any more help or ideas!
A potentially simpler solution could be to keep them in a single sequence and simply adjust the duration on the talk nodes. You can also add a Wait node just in case, otherwise the text will appear instantly as the previous one disappeared.
This approach can work if you intend to control the dialogue from a single graph and you aren’t expecting too much in the form of events or dynamic interactions (although that can also be done with custom actions or events in the graph and adding wait for event when needed)
Thanks Laura and Shanee on the quick replies. I think the event node idea might be something I will try to explore moving forwards since I want more dynamism in my project i.e. it might not always be NPC1 speaking followed by NPC2 - it could be a combination of NPCs depending on the scenario; for more context, the game simulates a strategy team-fighting environment where the Player controls a team and every input they give will require certain coordinations between the teammates.