### **Using the Dialogue Tree Editor** The DialogueTreeEditorWindow is a custom Unity Editor tool that lets you visualize and edit GameObject-based dialogue trees in a graph view. It displays nodes from a dialogueRoot, shows connections via choices, and provides buttons and context menus to modify the structure directly. Go to **[[7.Dialogue Visual Node Editor]]** for a detailed description of the **[[DialogueTreeEditorWindow.cs]]**. #### Setup 1. Open the Editor: - In the Unity Editor, go to Window > Dialogue Tree Editor. - A new window titled “Dialogue Tree Editor” opens with a graph view and a toolbar. 2. Select DialogueRoot: - In the Hierarchy, select your dialogueRoot GameObject (e.g., Greeting under Merchant-NPC). - In the Dialogue Tree Editor’s toolbar, drag this dialogueRoot into the Dialogue Root field (labeled as a GameObject property). - Click the Refresh button next to the field—nodes (e.g., Start, Buy) appear as boxes in the graph, connected by lines showing choice links. ![[Dialogue Tree Editor Network.png]] ### **Editing the Dialogue Tree** The graph displays each **DialogueNodeAuthoring** component as a node with its Id as the title. You can interact with nodes using buttons, right-click menus, and dragging to reposition them (positions save to their GameObject transforms). Here’s how to use it: #### **Node Features** Each node has a header (its Id) and three buttons below it: - **Add Choice:** - **What It Does**: Adds a new choice to the node’s **Choices** list in its **DialogueNodeAuthoring** component. - **How to Use**: - Click **Add Choice** on a node (e.g., **Start**). - A new choice appears in the Inspector under **Choices** with default **Choice Text** (e.g., "New Choice") and **Next Node** set to null. - In the graph, a new unconnected line extends—refresh to see updates after linking. - **Next Step**: In the Inspector, set **Choice Text** (e.g., "**Say goodbye**") and drag another node (e.g., **Farewell**) into **Next Node**. - **Select Object**: - **What It Does**: Highlights the corresponding GameObject in the Hierarchy and selects it in the Inspector. - **How to Use:** - Click Select Object on a node (e.g., Buy). - The Hierarchy focuses on that GameObject (e.g., **Merchant-NPC/Greeting/Buy**), and its **DialogueNodeAuthoring** properties appear in the Inspector. - Use Case: Edit node details (e.g., **Dialogue Text**, **Audio To Play**) without searching manually. - **Rename**: - **What It Does**: Changes the node’s **Id** and updates its GameObject name to match. - **How to Use**: - Click Rename on a node (e.g., Start). - A text field appears over the node—type a new Id (e.g., Intro) and press Enter. - The node’s title updates in the graph, the GameObject renames in the Hierarchy (e.g., Intro), and its DialogueNodeAuthoring.Id updates in the Inspector. - **Note**: Keep Id values unique—duplicates break choice links (refresh to fix). #### **Toolbar Buttons** - **Refresh**: Updates the graph to reflect changes in the dialogueRoot (e.g., new nodes, renamed IDs, added choices). - **Add Node**: Creates a new **DialogueNodeAuthoring** node under the selected Dialogue Root. - **How to Use**: Click Add Node—a new GameObject (e.g., Node_1) with DialogueNodeAuthoring appears under Dialogue Root in the Hierarchy and graph. - **Next Step**: Use Rename or the Inspector to set its Id and properties. - **Reset Layout**: Repositions all nodes in the graph to a default layout (e.g., a vertical or grid arrangement). - **How to Use**: Click Reset Layout—nodes rearrange automatically, updating their transform.position in the scene. #### **Right-Click Context Menus** - **Graph Background**: - Right-click an empty area in the graph: - Create Node: Adds a new DialogueNodeAuthoring node under Dialogue Root, same as Add Node but context-sensitive. - Appears at the click position in the graph and Hierarchy. - **Node Context Menu**: - Right-click a node (e.g., Start): - Disconnect All: Removes all Choices from the node’s DialogueNodeAuthoring, clearing outgoing connections in the graph. - Cut: Copies the node and removes it from the Hierarchy and graph (paste elsewhere with Paste). - Copy: Copies the node (including DialogueNodeAuthoring settings) to the clipboard. - Delete: Removes the node from the Hierarchy and graph. - Duplicate: Creates a copy of the node under Dialogue Root with the same settings (appends a number to the Id, e.g., Start_1). - Next Step: Use Refresh after changes to update the graph. - **Connection Context Menu**: - Right-click a connection line between nodes: - Delete: Removes the specific Choice linking the nodes from the source node’s Choices list. - Next Step: Refresh to see the updated graph. ![[Dialogue Tree Editor Node.png]] #### **Positioning Nodes** - **Drag Nodes**: Click and drag a node to reposition it in the graph. - **Visual Aid**: Use **Reset Layout** to tidy up, then fine-tune manually. #### **Workflow Example** 1. Open the editor, assign **Greeting** as **Dialogue Root**, and click **Refresh**. 2. Right-click the graph > **Create Node**—name it **Farewell** via **Rename**. 3. On Start, click **Add Choice**, set it to "**Say goodbye**" linking to **Farewell** in the Inspector. 4. Right-click Start > **Duplicate**—edit the new **Start_1** node via **Select Object**. 5. Right-click a connection > **Delete** to remove a choice, or **Disconnect All** on a node. 6. Click **Reset Layout**, then drag nodes for clarity—close when done. #### **Tips** - **Refresh Frequently**: After Hierarchy changes (e.g., adding nodes), click Refresh to sync the graph. - **Unique IDs**: Use Rename to avoid duplicate Id values—crucial for choice links. - **Context Power**: Right-click options speed up node management—use Duplicate for quick copies. - **Visual Only**: Node positions are for editing—gameplay follows Next Node connections. --- ### **Sample Hierarchy Diagrams** 1. **Initial Scene Setup:** ```text - Canvas-DialogueDisplay - DialoguePanel - CharacterPanel - DialogueManager - TypingAudioSource - Merchant-NPC ``` 2. **After Adding Greeting:** ```text - Merchant-NPC - Greeting (DialogueRoot, Environment) - Start (DialogueNodeAuthoring) - Buy (DialogueNodeAuthoring) ```