Best Practice for Setting up All Dialogue Nodes with the Same Settings?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Luseya
Posts: 38
Joined: Mon May 29, 2023 6:02 pm

Best Practice for Setting up All Dialogue Nodes with the Same Settings?

Post by Luseya »

Hello!

I was wondering what the best approach would be to set up all dialogue nodes with the same settings, meaning that, whenever I create a dialogue node, it would automatically have specific conditions, scripts, or events attached to it.

The context is that for my game, whenever the Player talks to an NPC, they lose a little bit of HP for each dialogue node, so I have to attach a script to the Unity events section every time I create a node. I would need to customize the value for the HP depending on the NPC and specific node, as some nodes cause more damage then others.

My programmer was going to modify the scripts that come with the Dialogue System, but I want to check here first before we touch that. I wasn't sure if there was a setting somewhere in the GUI, and if not, if we do have to modify your code, is there a specific way to handle it?

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

Re: Best Practice for Setting up All Dialogue Nodes with the Same Settings?

Post by Tony Li »

Hi,

I strongly recommend against directly modifying Dialogue System scripts. You'll lose your modifications whenever you update the Dialogue System.

The Dialogue System provides several code hooks to add your own code with having to directly modify the Dialogue System code.

Instead of using OnExecute() UnityEvents, you could add a script with an OnConversationLine(Subtitle) method to the Dialogue Manager or hook into the C# event DialogueManager.instance.conversationLinePrepared to perform the action. You could also add a custom field such as "Damage" to your dialogue entry template that specifies how much HP to subtract. Example:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
public class LoseHPEachDialogueEntry : MonoBehaviour
{
    void OnConversationLine(Subtitle subtitle)
    {
        bool isStartEntry = subtitle.dialogueEntry.id == 0;
        int damage = Field.LookupInt(subtitle.dialogueEntry.fields, "Damage");
        if (damage > 0 && !isStartEntry)
        {
            // ... your code here to inflict damage ...
        }
    }
}
Luseya
Posts: 38
Joined: Mon May 29, 2023 6:02 pm

Re: Best Practice for Setting up All Dialogue Nodes with the Same Settings?

Post by Luseya »

Okay got it! Thanks Tony!
User avatar
Tony Li
Posts: 23238
Joined: Thu Jul 18, 2013 1:27 pm

Re: Best Practice for Setting up All Dialogue Nodes with the Same Settings?

Post by Tony Li »

Glad to help!
Post Reply