0 votes

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
Godot version 3.4.4
in Engine by (1,877 points)
edited by

1 Answer

0 votes

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.

by (1,877 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.