Another way to avoid duplicate quests

Edit: I’ve followed and finished the course now. Sam has another (more robust) way of doing this and detecting actual progress. The only thing missing in that way is the root node changing. I’m keeping this up however since it might come in handy for someone out there.

Another way of avoiding duplicate quests and spicing up your conversations is to add the following code to AIConversant.cs

note: for these examples I use m_ for my private variables so anything that starts with m_ is basically whatever Sam’s equivalent in the video is

public void SetDialogue(Dialogue newDialogue)
{
    m_Dialogue = newDialogue;
}

This will allow you to hook up a new dialogue when triggering an event.
But the fun doesn’t stop there, there are now 2 ways to hook up this new dialogue.
Either you add it in the “GiveQuest” trigger event or you convert the OnExitActions to an array / list so you can have multiple things triggering independently.

this means you can replace

[SerializeField] private string m_OnExitAction;

with

[SerializeField] private string[] m_OnExitActions;

and

public string GetOnExitAction()
{
    return m_OnExitAction;
}

with

public IEnumerable GetOnExitActions()
{
    return m_OnExitActions;
}

now back in PlayerConversant you can replace the code that is in TriggerExitAction with the following

if (m_CurrentNode != null)
{
    foreach (string exitAction in m_CurrentNode.GetOnExitActions())
    {
        TriggerAction(exitAction);
     }
}

Now you are able to hook up multiple Dialogue triggers each doing it’s own thing even if there are multiple things you want to do on 1 node. Of course you can do the same with the OnEnterActions method

Maybe it doesn’t suit everyone’s use case but I felt like it gives a bit more flexibility and hope that sharing this helps someone :slight_smile:

4 Likes

Thank your for this! You put in so much detail that this will help everyone.

Privacy & Terms