Trying to work with GraphEdit/GraphNode

Godot Version

4.2

Question

Hey all! I’ve got a dialogue system I made not too long ago, works just fine for what I need but its a pain to author in. Its basically just an Array where I add on a single response at a time, its not too bad but makes tracking branching dialogue extremely difficult.

So I want to switch to a visual system for making the branching dialogue! I have looked some of the plugins that are around for dialogue management already, but none of them work well with the rest of my systems. I am working on a multiplayer game, so the saving and loading of progress in dialogue gets weird with some of these other plugins. Which means I need to make my own, what joy!

I have the initial parts of it working, where I can open a window and populate it with basic nodes. But it seems like it should come in with ports, and I am not getting any. And I can’t seem to find any information at all online. It looks like plugin designing is very very hard to find info on. Is there any info at all on how to create a dialogue plugin?

My current Code:
@tool
extends EditorPlugin

var graph_edit: GraphEdit

func _enter_tree():
graph_edit = GraphEdit.new()
graph_edit.set_size(Vector2(600, 400))

graph_edit.size_flags_horizontal = Control.SIZE_EXPAND_FILL
graph_edit.size_flags_vertical = Control.SIZE_EXPAND_FILL
graph_edit.minimap_enabled = false

add_control_to_dock(DOCK_SLOT_RIGHT_BL, graph_edit)

create_test_nodes()

func create_test_nodes():
for i in range(3):
var node = GraphNode.new()
node.title = "Dialogue Node " + str(i + 1)
graph_edit.add_child(node)

	node.set_slot(0, true, 0, Color.RED, true, 0, Color.BLUE)
	node.set_slot(1, true, 0, Color.GREEN, true, 0, Color.YELLOW)

But this is what the nodes look like:
image

So I am not seeing any of the ports. Any ideas on what to do here?

Any tutorials to follow for making GraphEdit things?

The graph nodes have to have control children to have slots open. Try adding a Control or Label as a child of the nodes.

1 Like

Ah that did it! Thanks! My brain has been fried from this long day, must be why I didn’t think of something so simple haha

image

I at least get the first set of slots, so good progress!

Will have to figure out how make them connect, and how to display more slots. But off to a great start!

1 Like

It’s a strange system, but it works alright for labels. I’ve done something similar with a dialogue system too

1 Like

How did you get the nodes to connect to one another? I can drag from a port, but when I drop it on another port it never connects.

You have to connect to the GraphEdit’s connection_request signal, and use the GraphEdit’s connect_node function to finalize such connections

1 Like

Oh interesting! Thanks!

Where did you learn everything for GraphEdit? A tutorial or just poking around? I feel like I’m going to have a few more questions haha

Poking around, reading the docs

1 Like