[RESOLVED] GraphNode multiple slots

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DaddyMonster

Hi all!

Just need to add multiple slots to GraphNodes and space them out nicely. Context is I’ve got a neural net and I’m looking to use Godot’s GraphEdit nodes to visualise / live edit the network in the UI.

I’ve used GraphEdit’s set_slot() which handles the settings fine but to add new slots the docs only say:

To create the slot, add a Control-derived child to the GraphNode.

Bit weird but ok. I added Control nodes as a child and sure enough, lots of slots, but the spacing is wrong, and the new ones are bunched up at the bottom. I’ve tried adjusting the margins and other settings on the control nodes to no avail. Also, the first node seems to be with the GraphNode and not a Control. It’s all very odd.

What’s the right way of doing this?

In case seeing the code helps:

var x_offset = 100
var y_offset = 100

func _ready():
	var layers = car.brain.layers
	var x = 0
	for l in layers:
		var y = 0
		for neu in l.neurons:
			var n = node.instance()
			n.offset = Vector2(x, y)
			$GraphEdit.add_child(n)
			for i in neu.weights.size():
				var c = Control.new()
				n.add_child(c)
				n.set_slot(i, true, 0, Color(1, 0, 0, 1), false, 0, Color(1, 0, 0, 1))
			y += y_offset
		x += x_offset
:bust_in_silhouette: Reply From: DaddyMonster

Got it, you can set the Y on rect_min_size on the Control child. First I had to disable the automatically created port and just use the ones I added.

The GraphEdit / GraphNode architecture needs a bit of a rework imho, it’s all a bit rickety. Unfortunately I’m not a C++ coder or I’d have a stab at it. Hopefully some nice person will give it some tlc after 4.0.