GraphEdit provides tools for creation, manipulation, and display of various graphs. Its main purpose in the engine is to power the visual programming systems, such as visual shaders, but it is also available for use in user projects.
GraphEdit by itself is only an empty container, representing an infinite grid where GraphNodes can be placed. Each GraphNode represents a node in the graph, a single unit of data in the connected scheme. GraphEdit, in turn, helps to control various interactions with nodes and between nodes. When the user attempts to connect, disconnect, or delete a GraphNode, a signal is emitted in the GraphEdit, but no action is taken by default. It is the responsibility of the programmer utilizing this control to implement the necessary logic to determine how each request should be handled.
Performance: It is greatly advised to enable low-processor usage mode (see OS.low_processor_usage_mode) when using GraphEdits.
Emitted at the beginning of a GraphElement's movement.
Emitted at the end of a connection drag.
Emitted at the beginning of a connection drag.
Emitted when user drags a connection from an input port into the empty space of the graph.
Emitted to the GraphEdit when the connection between the from_port
of the from_node
GraphNode and the to_port
of the to_node
GraphNode is attempted to be created.
Emitted when user drags a connection from an output port into the empty space of the graph.
Emitted when this GraphEdit captures a ui_copy
action (Ctrl + C by default). In general, this signal indicates that the selected GraphElements should be copied.
Emitted when this GraphEdit captures a ui_cut
action (Ctrl + X by default). In general, this signal indicates that the selected GraphElements should be cut.
Emitted when this GraphEdit captures a ui_graph_delete
action (Delete by default).
nodes
is an array of node names that should be removed. These usually include all selected nodes.
Emitted to the GraphEdit when the connection between from_port
of from_node
GraphNode and to_port
of to_node
GraphNode is attempted to be removed.
Emitted when this GraphEdit captures a ui_graph_duplicate
action (Ctrl + D by default). In general, this signal indicates that the selected GraphElements should be duplicated.
Emitted at the end of a GraphElement's movement.
Emitted when the GraphFrame frame
is resized to new_rect
.
Emitted when one or more GraphElements are dropped onto the GraphFrame named frame
, when they were not previously attached to any other one.
elements
is an array of GraphElements to be attached.
Emitted when the given GraphElement node is deselected.
Emitted when the given GraphElement node is selected.
Emitted when this GraphEdit captures a ui_paste
action (Ctrl + V by default). In general, this signal indicates that previously copied GraphElements should be pasted.
Emitted when a popup is requested. Happens on right-clicking in the GraphEdit. at_position
is the position of the mouse pointer when the signal is sent.
Emitted when the scroll offset is changed by the user. It will not be emitted when changed in code.
SCROLL_ZOOMS = 0
Mouse Wheel will zoom, Ctrl + Mouse Wheel will move the view.
SCROLL_PANS = 1
Mouse Wheel will move the view, Ctrl + Mouse Wheel will zoom.
GRID_PATTERN_LINES = 0
Draw the grid using solid lines.
GRID_PATTERN_DOTS = 1
Draw the grid using dots.
If true
, the lines between nodes will use antialiasing.
The curvature of the lines between the nodes. 0 results in straight lines.
The thickness of the lines between the nodes.
The connections between GraphNodes.
A connection is represented as a Dictionary in the form of:
Connections with keep_alive
set to false
may be deleted automatically if invalid during a redraw.
The pattern used for drawing the grid.
If true
, the minimap is visible.
The opacity of the minimap rectangle.
The size of the minimap rectangle. The map itself is based on the size of the grid area and is scaled to fit this rectangle.
Defines the control scheme for panning with mouse wheel.
If true
, enables disconnection of existing connections in the GraphEdit by dragging the right end.
The scroll offset.
If true
, the button to automatically arrange graph nodes is visible.
If true
, the grid is visible.
If true
, buttons that allow to configure grid and snapping options are visible.
If true
, the menu toolbar is visible.
If true
, the button to toggle the minimap is visible.
If true
, buttons that allow to change and reset the zoom level are visible.
If true
, the label with the current zoom level is visible. The zoom level is displayed in percents.
The snapping distance in pixels, also determines the grid line distance.
If true
, enables snapping.
The current zoom value.
The upper zoom limit.
The lower zoom limit.
The step of each zoom level.
Virtual method which can be overridden to customize how connections are drawn.
Returns whether the mouse_position
is in the input hot zone.
By default, a hot zone is a Rect2 positioned such that its center is at in_node
.GraphNode.get_input_port_position()(in_port
) (For output's case, call GraphNode.get_output_port_position() instead). The hot zone's width is twice the Theme Property port_grab_distance_horizontal
, and its height is twice the port_grab_distance_vertical
.
Below is a sample code to help get started:
Returns whether the mouse_position
is in the output hot zone. For more information on hot zones, see _is_in_input_hotzone().
Below is a sample code to help get started:
This virtual method can be used to insert additional error detection while the user is dragging a connection over a valid port.
Return true
if the connection is indeed valid or return false
if the connection is impossible. If the connection is impossible, no snapping to the port and thus no connection request to that port will happen.
In this example a connection to same node is suppressed:
Allows the connection between two different port types. The port type is defined individually for the left and the right port of each slot with the GraphNode.set_slot() method.
See also is_valid_connection_type() and remove_valid_connection_type().
Allows to disconnect nodes when dragging from the left port of the GraphNode's slot if it has the specified type. See also remove_valid_left_disconnect_type().
Allows to disconnect nodes when dragging from the right port of the GraphNode's slot if it has the specified type. See also remove_valid_right_disconnect_type().
Rearranges selected nodes in a layout with minimum crossings between connections and uniform horizontal and vertical gap between nodes.
Attaches the element
GraphElement to the frame
GraphFrame.
Removes all connections between nodes.
Create a connection between the from_port
of the from_node
GraphNode and the to_port
of the to_node
GraphNode. If the connection already exists, no connection is created.
Connections with keep_alive
set to false
may be deleted automatically if invalid during a redraw.
Detaches the element
GraphElement from the GraphFrame it is currently attached to.
Removes the connection between the from_port
of the from_node
GraphNode and the to_port
of the to_node
GraphNode. If the connection does not exist, no connection is removed.
Ends the creation of the current connection. In other words, if you are dragging a connection you can use this method to abort the process and remove the line that followed your cursor.
This is best used together with connection_drag_started and connection_drag_ended to add custom behavior like node addition through shortcuts.
Note: This method suppresses any other connection request signals apart from connection_drag_ended.
Returns an array of node names that are attached to the GraphFrame with the given name.
Returns the closest connection to the given point in screen space. If no connection is found within max_distance
pixels, an empty Dictionary is returned.
A connection is represented as a Dictionary in the form of:
For example, getting a connection at a given mouse position can be achieved like this:
Returns the number of connections from from_port
of from_node
.
Returns the points which would make up a connection between from_node
and to_node
.
Returns an Array containing the list of connections that intersect with the given Rect2.
A connection is represented as a Dictionary in the form of:
Returns the GraphFrame that contains the GraphElement with the given name.
Gets the HBoxContainer that contains the zooming and grid snap controls in the top left of the graph. You can use this method to reposition the toolbar or to add your own custom controls to it.
Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their CanvasItem.visible property.
Returns true
if the from_port
of the from_node
GraphNode is connected to the to_port
of the to_node
GraphNode.
Returns whether it's possible to make a connection between two different port types. The port type is defined individually for the left and the right port of each slot with the GraphNode.set_slot() method.
See also add_valid_connection_type() and remove_valid_connection_type().
Disallows the connection between two different port types previously allowed by add_valid_connection_type(). The port type is defined individually for the left and the right port of each slot with the GraphNode.set_slot() method.
See also is_valid_connection_type().
Disallows to disconnect nodes when dragging from the left port of the GraphNode's slot if it has the specified type. Use this to disable disconnection previously allowed with add_valid_left_disconnect_type().
Disallows to disconnect nodes when dragging from the right port of the GraphNode's slot if it has the specified type. Use this to disable disconnection previously allowed with add_valid_right_disconnect_type().
Sets the coloration of the connection between from_node
's from_port
and to_node
's to_port
with the color provided in the activity theme property. The color is linearly interpolated between the connection color and the activity color using amount
as weight.
Sets the specified node
as the one selected.