Giter VIP home page Giter VIP logo

dialoguetrees's Introduction

Dialogue Trees C#

Dialogue Trees is a plugin that adds a graph-based dialogue editor

Please Note:

Dialogue Trees is still in early development. This means that you will likely encounter bugs and issues, and that compatiblity breaking changes will happen in the future.

Features

  • Simple, understandable node-set
  • Powerful actions and variables
  • Compact save structure that doesn't bloat your scene files
  • A custom graph-arranger
  • Customiseable and extendible

Getting Started

To begin with, you need to download the assets/dialogue_trees folder and add it to your project. After that, build your C# project and activate the plugin.

To start making dialogue, open up a scene and add a DialogueTree node. Click on the node, then in the inspector click 'Tree Data' and create a new TreeData.

Now, you should see an option in the bottom tab that says 'Dialogue' (the bottom tab is where you usually see Output and Debugger). When you click 'Dialogue' you will see the dialogue editor open.

In the editor, you can finally create nodes by right clicking, or by clicking "Add Node".

Dialogue Nodes

There are currently 10 dialogue nodes by default, this is a list of all of them and a basic description of each.

Node Description
Start The start node is activated when DialogueTree.StartDialogue() is called. There can only be one start node, and it cannot be deleted.
Switch Awaits input from the player, and compares that input to a list of options. Options support regex, which can be useful if you are using a system where the player writes a response. For more fixed systems, you can get the list of options by calling DialogueTree.GetInputOptions().
Output Outputs text and a character's name by sending the DialogueTree.DialogueOutput signal.
Call Activates a selected Function node. Mainly exists as a tool to make dialogue trees more readable.
Function Acts as a reciever for a Call node.
Action Activates a selected DialogueAction. DialogueActions are nodes that need to be added as children of a dialogue tree, and allow a dialogue tree to interact with the scene tree. DialogueActions are also designed to be very easy to extend, so you can create your own for certain situations.
Condition Checks if a selected DialogueCondition is true, DialogueConditions are nodes that need to be added as children of a dialogue tree, and allow a dialogue tree to be affected by the state of the scene tree. Dialogue Conditions are designed to be very easy to extend, so you can create your own for certain situations.
Variable Defines a variable that can be modified and compared by Variable Setters and Variable Conditions.
Variable Setter Modifies the value of a varaible.
Variable Condition Checks if a variable passes a certain condition.

Using the DialogueTree API

On its own, a DialogueTree will do nothing. It needs to be activated externally, and its inputs and outputs need to be handled via the API.

There are a few functions you will need to know, here's a list of them:

Function Description
void StartDialogue () Starts the dialogue by activating the Start node.
void EndDialogue () Prematurely ends the dialogue.
void SendInput (string input, params Variant[] parameters) Sends an input string to the active node. Parameters is not used by default. Some nodes, like output nodes, may require an empty input to signal that they can continue the dialogue.
DialogueInputOption[] GetInputOptions () Gets a list of options that can be passed into SendInput (). The Parameters field of DialogueInputOption is not used by default. Some nodes, like output nodes, that need an empty input to continue will include that empty input in this list of options.

There are also some signals that you will need to know, here's a list of them:

Signal Parameters Description
DialogueEnded Called when the dialogue ends, usually because a node had nowhere to output to, but can also be called by EndDialogue ().
DialogueOutput string output, string character, Array parameters Called when the dialogue tree outputs text, by default this is only called by Output nodes, and parameters is not used. By default, this also signals that an empty input is required to continue the dialogue.

Example

Here is a basic script that executes dialogue trees by printing outputs to the console and by choosing the first possible input every time.

using Ardot.DialogueTrees;
using Godot;

public partial class DialogueReader : Node
{
	[Export]
	public DialogueTree DialogueTree;

	public override void _Ready()
	{
		DialogueTree.DialogueOutput += (string dialogue, string character, Godot.Collections.Array parameters) => GD.Print($"{character}: {dialogue}");
		DialogueTree.StartDialogue ();

		while (DialogueTree.DialogueActive)
		{
			DialogueInputOption inputOption = DialogueTree.GetInputOptions()[0];
			DialogueTree.SendInput(inputOption.Input, inputOption.Parameters);
		}
	}
}

Settings and Customisation

DialogueTrees was designed around being easily extended and modified, so you can add your own nodes, modify or remove existing nodes, make your own variable types, and set up default graphs.

Settings Resource

At this point in time, settings are handled by a resource at res://addons/dialogue_trees/dialogue_tree_settings.tres. This resource has two properties, Dialogue Node Data and Default Tree.

Default Tree

Every new TreeData will be a copy of the Default Tree. You can set this by using the node creation menu and pressing 'Save Selected'. After saving the tree, you can drag the file into Default Tree, and it will become the default for any new TreeData resources.

Dialogue Node Data

Every Dialogue Node is defined by a DialogueNodeData resource, stored in Dialogue Node Data. Each DialogueNodeData has several properties. Here's is a list of them:

Property Type Description
Dialogue Node Name StringName The name of the node. This will display when in the node-creation menu.
Dialogue Node Save Name StringName An abbreviation of the name. Usually 3 characters long, must be unique, so make sure it is not the same as other node save-names. If you change this value, any graphs that include this node will break.
Dialogue Node Scene PackedScene A scene that contains the DialogueNode as the root node (the node's script must inherit DialogueNode). This will be instantiated directly into the graph.
Instance Script Script A Script that must inherit DialogueNodeInstance. This script provides the runtime functionality for the node.

Custom Variable Types

Variable nodes are designed with the ability to add multiple different value types. Currently, you will have to inherit the DialogueVariableNode script and override some functions to add your own. This system is likely to be overhauled in the future.

Gallery

A simple branching dialogue tree

image

dialoguetrees's People

Contributors

ardot66 avatar geminisquishgames avatar

Stargazers

Iván  avatar Samm avatar Plagueheart avatar  avatar Lixiang.Zhao avatar 白昼姓姜暗夜魔王 avatar Matias Lavik (马蹄) avatar

Watchers

 avatar

dialoguetrees's Issues

cannot load at godot 4.2.2

"
Unable to load addon script from path: 'res://addons/dialogue_trees/scripts/core/DialogueTreesPlugin.cs'. This might be due to a code error in that script.
Disabling the addon at 'res://addons/dialogue_trees/plugin.cfg' to prevent further errors.
"

verison: Godot_v4.2.2-stable_mono_win64_console
OS: win10, linux mint 21.3
.net sdk: 8.0

Unable to load addon script from path: 'res://addons/dialogue_trees/scripts/core/DialogueTreesPlugin.cs'. This might be due to a code error in that script. Disabling the addon at 'res://addons/dialogue_trees/plugin.cfg' to prevent further errors.

Hello, I have never used a C# addon, I'm not sure if I'm doing something wrong but I simply installed the addon from godot plugins and tried to enable it from the plugins menu unfortunately I got the "Unable to load addon script from path: 'res://addons/dialogue_trees/scripts/core/DialogueTreesPlugin.cs'. This might be due to a code error in that script. Disabling the addon at 'res://addons/dialogue_trees/plugin.cfg' to prevent further errors." I did this on a empty project so I don't think this is an error on my part. I checked that file and couldn't find any suspects.

Editor (4.3 beta) crashes with access violation when trying to load previously created tree in scene

Platform: Windows 11

Created a DialogueTree node in the editor in a scene. Added code to start the dialogue and display text. Went back to the editor after some time and switched back into the scene with the DialogueTree. The editor crashes to desktop (reliably crashes whenever I select the DialogueTree node in the scene when the project is open in the editor).

Godot Engine v4.3.beta1.mono.official.a4f2ea91a - https://godotengine.org
OpenGL API 3.3.0 - Build 31.0.101.4575 - Compatibility - Using Device: Intel - Intel(R) Iris(R) Xe Graphics

Editing project: D:/dev/dev/drpg
Godot Engine v4.3.beta1.mono.official.a4f2ea91a - https://godotengine.org
Vulkan 1.3.242 - Forward+ - Using Device #1: NVIDIA - NVIDIA T550 Laptop GPU

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Godot.NativeInterop.NativeFuncs.godotsharp_method_bind_ptrcall(IntPtr, IntPtr, Void**, Void*)
   at Godot.NativeCalls.godot_icall_3_764(IntPtr, IntPtr, IntPtr, Godot.NativeInterop.godot_bool, Int32)
   at Godot.Node.AddChild(Godot.Node, Boolean, InternalMode)
   at Ardot.DialogueTrees.DialogueGraph.<LoadTree>g__AddDialogueNode|26_0(Godot.Node, Int32, <>c__DisplayClass26_0 ByRef)
   at Ardot.DialogueTrees.DialogueGraph.LoadTree(Ardot.DialogueTrees.DialogueTreeData, Boolean, Godot.Collections.Array`1<Godot.Node>)
   at Ardot.DialogueTrees.DialogueTreeDock.LoadTree(Ardot.DialogueTrees.DialogueTree)
   at Ardot.DialogueTrees.DialogueTreesPlugin._Edit(Godot.GodotObject)
   at Godot.EditorPlugin.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name ByRef, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant ByRef)
   at Ardot.DialogueTrees.DialogueTreesPlugin.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name ByRef, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant ByRef)
   at Godot.Bridge.CSharpInstanceBridge.Call(IntPtr, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, Int32, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.go)

Error: Cannot open file 'res://addons/dialogue_trees/scenes/dialogue_nodes/subscenes/case_text.tscn'.

Cannot open file 'res://addons/dialogue_trees/scenes/dialogue_nodes/subscenes/case_text.tscn'.

I think you mean 'res://addons/dialogue_trees/scenes/dialogue_nodes/helper_nodes/case_text.tscn'

in DialogSwitchNode.cs @ line 14 should be:

_caseTextPath = $"{DialogueTreesPlugin.DialogueTreesPluginPath}/scenes/dialogue_nodes/helper_nodes/case_text.tscn",

Did a pull req here: #2 (figured helper_nodes sounded more descriptive than subscenes, but I'm not sure of the context or which you want to change, 🤔)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.