Dialogues with Multiple Root Elements, and counting killed enemies

How do we make a second root node (to start a new conversation depending on where the player is in the Quest system), or at least swap out our dialogues given to us by Quest givers, after we finish their quests?

Also, how do we count how many killed enemies has our player killed during a Quest?

Check out this thread: Tracking kills for Quests? - #17 by Mythran

Making a second root node (or as many as you want) is actually relatively easy… just create a child node from the root, and then delete the connection.

The tricky part is GETTING all of the root nodes.

Here’s a hot take on this, though it may be smarter to cache these values somehow:

        public IEnumerable<DialogueNode> GetRootNodes()
        {
            foreach (DialogueNode node in GetAllNodes())
            {
                bool isChild = false;
                foreach (DialogueNode lookupNode in GetAllNodes())
                {
                    
                    if (lookupNode.GetChildren().Contains(node.name))
                    {
                        isChild = true;
                        break;
                    }
                }

                if (!isChild) yield return node;
            }
        }

This searches through each node, then searches through each node against that node to see if it is a child node of another node. If it is, then it’s not returned, if it’s a root node, then it won’t be a child of any other node.
Then you can filter the results of GetNodes() to find the best node to display.

Privacy & Terms