Filtering Dialogues by TAGs in Unity Dialogue System

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
LeonZhu
Posts: 3
Joined: Wed Jun 15, 2022 5:36 am

Filtering Dialogues by TAGs in Unity Dialogue System

Post by LeonZhu »

Hello everyone,

I'm currently working with a dialogue system plugin for Unity and I have a specific requirement regarding TAGs for dialogues. I would like to implement a feature that allows filtering dialogues based on the TAGs assigned to the characters involved in the conversation.

Here’s what I have in mind:

TAG Classification: Each character should have several categories of TAGs. Initially, I have defined the following:

Type: Friendly Creature, Hostile Creature, Mechanism, Treasure
Wealth: Poor, Average, Rich, No Assets
Threat: Strong, Weak
TAG Search:

First, I need to search for the TAGs of the actor involved in the dialogue.
Then, I want to filter the available dialogues based on matching TAGs. For example, if an actor has TAGs like Friendly Creature, Rich, and Weak, I want to retrieve dialogues that match any combination of these TAGs.
Has anyone implemented something similar or can provide guidance on how to approach this? Any insights or examples would be greatly appreciated!

Thank you!
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Filtering Dialogues by TAGs in Unity Dialogue System

Post by Tony Li »

Hi,

You can either use Boolean fields in your dialogue database or Text fields. Boolean fields will require more fields, but it may be easier to work with. Here's an example:

tags1.png
tags1.png (44.7 KiB) Viewed 54 times
tags2.png
tags2.png (107.75 KiB) Viewed 54 times

I recommend adding these fields to your Template.

To make a list of conversations, you can loop through the conversations and record the conversations whose tags match the character's tags. Example:

Code: Select all

static string[] FieldNames = new string[] { "Friendly", "Hostile", "Mechanism", "Treasure", "Poor", "Rich", "Strong", "Weak" };

public List<Conversation> FilterConversations(Actor actor)
{
    var list = new List<Conversation>();
    foreach (var conversation in DialogueManager.masterDatabase.conversations)
    {
        // Assume conversation is valid until we check tags:
        bool isValid = true;
        foreach (var fieldName in FieldNames)
        {
            bool actorValue = actor.LookupBool(fieldName);
            bool conversationValue = conversation.LookupBool(fieldName);
            if (actorValue == true && conversationValue == false)
            {
                // This conversation doesn't have a tag that the actor has, so it's not valid:
                isValid = false;
                break;
            }
        if (isValid) list.Add(conversation);
    }
    return list;
}
Post Reply