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()
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()
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);
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!!
Top comments (0)