DEV Community

Sunder Iyer
Sunder Iyer

Posted on

2 3

TIL Godot GraphEdit Gaffes

2021-03-11

The GraphEdit and GraphNodes sure have their...idiosyncrasies.

I got stumped for a bit because I wanted to remove all the GraphNodes in a GraphEdit to perform a clear so I did a children-loop remove.

# self is the graphedit control
for child in self.get_children():
    self.remove_child(child)
    child.queue_free()
Enter fullscreen mode Exit fullscreen mode

Yeah, don't do this. This is because the GraphEdit comes with children already - a GraphEditFilter and Control; you get hard crashes when you remove those and mess with the control gg ez.

I found this works better.

for child in self.get_children():
    if (child is GraphNode):
        self.remove_child(child)
        child.queue_free()
Enter fullscreen mode Exit fullscreen mode

Gonna make it a two-fer-one since I slept before writing an entry yesterday!
This one was a bit tricky but I learned you cannot set the position of children GraphNodes in a GraphEdit. Basically, I setup an auto-connecting GraphNode and wanted to position them nicely around the node it was connected to.
Intended Goal

Aboved: what I wanted (and eventually got)

In order to accomplish this, the offset property needed to be used and not position. This is because the GraphEdit sets the actual position of the GraphNode in order to set the proper scaled/scrolled position of it. The following C++ code shows this in action.

void GraphEdit::_update_scroll_offset() {
    // . . .
    Point2 pos = gn->get_position_offset() * zoom;
    pos -= Point2(h_scroll->get_value(), v_scroll->get_value());
    gn->set_position(pos);
Enter fullscreen mode Exit fullscreen mode

What made this very trippy was setting the position worked(!) at one point but I suspect that removing all children in the GraphEdit allowed this to happen. Once I fixed that issue, the placement issue popped up. It got resolved but there's still more work to be done! Stay tuned!!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay