Godot Version
v4.4.stable.official [4c311cbee]
Question
Hello! I am writing editor plugin for my project and I had been faced with this problem.
It is a GraphEdit inheritor. And I have this code:
@tool
class_name GraphDataEdit
extends GraphEdit
@export var graph_data: GraphData
@export var node_template: PackedScene
var undo_redo: UndoRedo = UndoRedo.new()
func _delete_selected_nodes() -> void:
undo_redo.create_action("Delete Nodes")
var selected_nodes := _collect_selected_nodes()
for node in selected_nodes:
undo_redo.add_do_method(graph_data.nodes.erase.bind(node.data))
undo_redo.add_do_method(node.queue_free)
undo_redo.add_undo_method(graph_data.nodes.append.bind(node.data))
undo_redo.add_undo_method(self._restore_node.bind(node))
undo_redo.add_do_method(graph_data.update_connections.bind(get_connection_list()))
undo_redo.add_undo_method(graph_data.update_connections.bind(get_connection_list()))
undo_redo.commit_action()
graph_data.update_connections(get_connection_list())
# GraphDataNode is GraphNode inheritor, GraphNodeData is a Resource with node data
func create_node(node_data: GraphNodeData, first_load: bool = false) -> GraphDataNode:
var node: GraphDataNode = node_template.instantiate()
var node_name = str(node_data.node_id)
node.initialize(node_name, node_data, undo_redo)
if not first_load:
undo_redo.create_action("Create Node")
undo_redo.add_do_method(add_child.bind(node))
undo_redo.add_undo_method(remove_child.bind(node))
undo_redo.commit_action()
node.selected = true
else:
add_child(node)
node.tree_entered.connect(_on_node_entered_tree.bind(node))
return node
func _on_node_entered_tree(node) -> void:
node.owner = self.owner
func _collect_selected_nodes() -> Array[GraphDataNode]:
var result: Array[GraphDataNode] = []
for child in get_children():
if child is not GraphDataNode:
continue
if child.selected:
result.append(child as GraphDataNode)
return result
And when I am calling _delete_selected_nodes()
this thing happening:
ERROR: Attempt to disconnect a nonexistent connection from '87490663:<GraphNode#16684907847369>'. Signal: 'item_rect_changed', callable: 'CanvasItem::queue_redraw'.
So, it handles node to delete corretly, but when queue_free()
called, it trying to disconnect node from connection that I have never used. I am out of ideas what to do.
Will appreciate any help with this)