Last Updated: 02/24/2024
Publisher: cherrydev (Oleg Vishnivetsky)
π‘ **About: Nodes-based dialog system** asset is a tool that allows game developers to create branching dialog trees for their game characters easily. It is a visual editor that allows users to create and connect nodes to build conversations between characters in their game. Each node represents a piece of dialog, and the connections between nodes determine the flow of the conversation. ββββββββββββββββββββββββββββββββA **Node Editor** presents an editable graph, displaying nodes and the connections between their attributes. You can create simple sentence node or node with answers to build your own dialog.
You can check video tutorial on youtube, but this video is little outdated: Click here.
- Right-click to the assets folder.
- Go to Create/ScribtableObjects/Nodes/NodeGraph.
- Double click on your new DialogNodeGraph assets and you are done!
- You can also go to Window/DialogNodeBasedEditor, but you still have to create NodeGraph SO and click on it.
- By holding the left mouse button you can move around the window.
- Right mouse button opens context menu. It has options such as βCreate sentence nodeβ, βCreate answer nodeβ, βSelect all nodesβ and βRemove selected nodesβ.
- To connect nodes together, hold down the right mouse button on the node and drag it to.
- Sentence node can only join one any other node (Has one parent and one child node).
- The node has the following parameters: 1. Name 2. Sentence 3. Sprite (You can leave it null).
- By clicking the βAdd external functionβ button, another field appears for the name of the function that you previously added (More on this below).
- Click the βRemove external functionβ button to remove external function π.
- Answer node has an infinite parent node, but child nodes depend on the number of answers in the node (Answer node canβt join to answer node).
- By clicking the "Add Answer" button, you will add another answer option (The number of answer options is unlimited).
- You can delete the last answer option by clicking the corresponding button.
- To use dialog system you can just drag and drop Dialog Prefab from the Prefab folder and call StartsDialog method from DialogBehaviour script that attached to this prefab.
π‘ It is recommended that another script call this method instead of doing it in the DialogBehaviour script. For example, as in the demo script.
// Test script to call StartDialog method
public class TestDialogStarter : MonoBehaviour
{
[SerializeField] private DialogBehaviour dialogBehaviour;
[SerializeField] private DialogNodeGraph dialogGraph;
private void Start()
{
dialogBehaviour.StartDialog(dialogGraph);
}
}
StartDialog method from the DialogBehaviour script. As you can see, you need to pass DialogNodeGraph as a parameter.
public void StartDialog(DialogNodeGraph dialogNodeGraph)
{
isDialogStarted = true;
if (dialogNodeGraph.nodesList == null)
{
Debug.LogWarning("Dialog Graph's node list is empty");
return;
}
onDialogStarted?.Invoke();
currentNodeGraph = dialogNodeGraph;
DefineFirstNode(dialogNodeGraph);
CalculateMaxAmountOfAnswerButtons();
HandleDialogGraphCurrentNode(currentNode);
}
- You can bind external functions to use them in sentence node. There is a method for this called BindExternalFunction. It takes as parameters the name of the function and the function itself. This method can then be used in a sentence node, it will be called along with this node.
π‘ You need to bind an external function before calling it.
public void BindExternalFunction(string funcName, Action function);
--------------------------------------------------------------------------------------
public class TestDialogStarter : MonoBehaviour
{
[SerializeField] private DialogBehaviour dialogBehaviour;
[SerializeField] private DialogNodeGraph dialogGraph;
private void Start()
{
dialogBehaviour.BindExternalFunction("Test", DebugExternal);
dialogBehaviour.StartDialog(dialogGraph);
}
private void DebugExternal()
{
Debug.Log("External function works!");
}
}
- In the inspector you can configure parameters such as:
- Dialog Char Dalay (float) - delay before printing characters or text printing speed
- Next Sentence Key Codes (List) - keys when pressed that load the next sentence
- Is Can Skipping Text (bool) - If true - when you press the keys, instantly print the current sentence
- OnDialogStarted and OnDialogEnded events.
π‘ You can assign all these parameters in code
βββββ Feel free to edit any code to suit your needs. If you find any bugs or have any questions, you can write about it to me by email, github or in reviews in the Unity Asset Store. I will also be pleased if you visit my itchio page. π
Gmail: [email protected]
Github: https://github.com/OlegVishnivetsky
Itch.io: https://oleg-vishnivetsky.itch.io/
Unity Asset Store: https://assetstore.unity.com/packages/tools/game-toolkits/node-based-dialog-system-249962
This file will be updated over time. If you write suggestions again.