Inheritance #
- AudioServer
- CameraServer
- ClassDB
- DisplayServer
- EditorFileSystemDirectory
- EditorInterface
- EditorPaths
- EditorSelection
- EditorUndoRedoManager
- EditorVCSInterface
- Engine
- EngineDebugger
- FramebufferCacheRD
- GDExtensionManager
- Geometry2D
- Geometry3D
- IP
- Input
- InputMap
- JNISingleton
- JSONRPC
- JavaClassWrapper
- JavaScriptBridge
- MainLoop (1)
- Marshalls
- MovieWriter
- NativeMenu
- NavigationMeshGenerator
- NavigationServer2D
- NavigationServer3D
- Node (21)
- OS
- OpenXRExtensionWrapperExtension
- OpenXRInteractionProfileMetadata
- Performance
- PhysicsDirectBodyState2D (1)
- PhysicsDirectBodyState3D (1)
- PhysicsDirectSpaceState2D (1)
- PhysicsDirectSpaceState3D (1)
- PhysicsServer2D (1)
- PhysicsServer2DManager
- PhysicsServer3D (1)
- PhysicsServer3DManager
- PhysicsServer3DRendering
ServerHandler
- ProjectSettings
- RefCounted (121)
- RenderData (2)
- RenderSceneData (2)
- RenderingDevice
- RenderingServer
- ResourceLoader
- ResourceSaver
- ResourceUID
- ScriptLanguage (1)
- ShaderIncludeDB
- TextServerManager
- ThemeDB
- TileData
- Time
- TranslationServer
- TreeItem
- UndoRedo
- UniformSetCacheRD
- WorkerThreadPool
- XRServer
- XRVRS
- AnimationMixer (2)
- AudioStreamPlayer
- CanvasItem (2)
- CanvasLayer (1)
- EditorFileSystem
- EditorPlugin (1)
- EditorResourcePreview
- HTTPRequest
- InstancePlaceholder
- MissingNode
- MultiplayerSpawner
- MultiplayerSynchronizer
- NavigationAgent2D
- NavigationAgent3D
- Node3D (31)
- ResourcePreloader
- ShaderGlobalsOverride
- StatusIndicator
- Timer
- Viewport (2)
- WorldEnvironment
- BaseButton (3)
- ColorRect
- Container (13)
- GraphEdit
- ItemList
- Label
- LineEdit
- MenuBar
- NinePatchRect
- Panel
- Range (6)
- ReferenceRect
- RichTextLabel
- Separator (2)
- TabBar
- TextEdit (1)
- TextureRect
- Tree
- VideoStreamPlayer
Table of contents
-
var clip_contents: bool = true -
var connection_lines_antialiased: bool = true -
var connection_lines_curvature: float = 0.5 -
var connection_lines_thickness: float = 4.0 -
var connections: Dictionary[] = [] -
var focus_mode = FOCUS_ALL -
var grid_pattern = GRID_PATTERN_LINES -
var minimap_enabled: bool = true -
var minimap_opacity: float = 0.65 -
var minimap_size: Vector2 = Vector2(240, 160) -
var panning_scheme = SCROLL_ZOOMS -
var right_disconnects: bool = false -
var scroll_offset: Vector2 = Vector2(0, 0) -
var show_arrange_button: bool = true -
var show_grid: bool = true -
var show_grid_buttons: bool = true -
var show_menu: bool = true -
var show_minimap_button: bool = true -
var show_zoom_buttons: bool = true -
var show_zoom_label: bool = false -
var snapping_distance: int = 20 -
var snapping_enabled: bool = true -
var zoom: float = 1.0 -
var zoom_max: float = 2.0736 -
var zoom_min: float = 0.232568 -
var zoom_step: float = 1.2 -
virtual const func _get_connection_line(to_position: Vector2) -> PackedVector2Array -
virtual func _is_in_input_hotzone(mouse_position: Vector2) -> bool -
virtual func _is_in_output_hotzone(mouse_position: Vector2) -> bool -
virtual func _is_node_hover_valid(to_port: int) -> bool -
func add_valid_connection_type(to_type: int) -> void -
func add_valid_left_disconnect_type(type: int) -> void -
func add_valid_right_disconnect_type(type: int) -> void -
func arrange_nodes() -> void -
func attach_graph_element_to_frame(frame: StringName) -> void -
func clear_connections() -> void -
func connect_node(keep_alive: bool = false) -> intError -
func detach_graph_element_from_frame(element: StringName) -> void -
func disconnect_node(to_port: int) -> void -
func force_connection_drag_end() -> void -
func get_attached_nodes_of_frame(frame: StringName) -> StringName[] -
const func get_closest_connection_at_point(max_distance: float = 4.0) -> Dictionary -
func get_connection_count(from_port: int) -> int -
const func get_connection_line(to_node: Vector2) -> PackedVector2Array -
const func get_connections_intersecting_with_rect(rect: Rect2) -> Dictionary[] -
func get_element_frame(element: StringName) -> GraphFrame -
func get_menu_hbox() -> HBoxContainer -
func is_node_connected(to_port: int) -> bool -
const func is_valid_connection_type(to_type: int) -> bool -
func remove_valid_connection_type(to_type: int) -> void -
func remove_valid_left_disconnect_type(type: int) -> void -
func remove_valid_right_disconnect_type(type: int) -> void -
func set_connection_activity(amount: float) -> void -
func set_selected(node: Node) -> void -
const SCROLL_ZOOMS = 0 enum PanningScheme -
const SCROLL_PANS = 1 enum PanningScheme -
const GRID_PATTERN_LINES = 0 enum GridPattern -
const GRID_PATTERN_DOTS = 1 enum GridPattern -
enum PanningScheme -
enum GridPattern -
signal begin_node_move() -
signal connection_drag_ended() -
signal connection_drag_started(is_output: bool) -
signal connection_from_empty(release_position: Vector2) -
signal connection_request(to_port: int) -
signal connection_to_empty(release_position: Vector2) -
signal copy_nodes_request() -
signal cut_nodes_request() -
signal delete_nodes_request(nodes: StringName[]) -
signal disconnection_request(to_port: int) -
signal duplicate_nodes_request() -
signal end_node_move() -
signal frame_rect_changed(new_rect: Rect2) -
signal graph_elements_linked_to_frame_request(frame: StringName) -
signal node_deselected(node: Node) -
signal node_selected(node: Node) -
signal paste_nodes_request() -
signal popup_request(at_position: Vector2) -
signal scroll_offset_changed(offset: Vector2) -
self["theme_override_colors/activity"] = Color(1, 1, 1, 1) as Color -
self["theme_override_colors/connection_hover_tint_color"] = Color(0, 0, 0, 0.3) as Color -
self["theme_override_colors/connection_rim_color"] = Color(0.1, 0.1, 0.1, 0.6) as Color -
self["theme_override_colors/connection_valid_target_tint_color"] = Color(1, 1, 1, 0.4) as Color -
self["theme_override_colors/grid_major"] = Color(1, 1, 1, 0.2) as Color -
self["theme_override_colors/grid_minor"] = Color(1, 1, 1, 0.05) as Color -
self["theme_override_colors/selection_fill"] = Color(1, 1, 1, 0.3) as Color -
self["theme_override_colors/selection_stroke"] = Color(1, 1, 1, 0.8) as Color -
self["theme_override_constants/connection_hover_thickness"] = 0 as int -
self["theme_override_constants/port_hotzone_inner_extent"] = 22 as int -
self["theme_override_constants/port_hotzone_outer_extent"] = 26 as int -
self["theme_override_icons/grid_toggle"] = icon as Texture2D -
self["theme_override_icons/layout"] = icon as Texture2D -
self["theme_override_icons/minimap_toggle"] = icon as Texture2D -
self["theme_override_icons/snapping_toggle"] = icon as Texture2D -
self["theme_override_icons/zoom_in"] = icon as Texture2D -
self["theme_override_icons/zoom_out"] = icon as Texture2D -
self["theme_override_icons/zoom_reset"] = icon as Texture2D -
self["theme_override_styles/menu_panel"] = style as StyleBox -
self["theme_override_styles/panel"] = style as StyleBox
GraphEdit #
is_instantiable, Node, core, not_builtin_classes
An editor for graph-like structures, using GraphNodes.
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.
Note: Keep in mind that Node.get_children will also return the connection layer node named _connection_layer due to technical limitations. This behavior may change in future releases.
Members #
var clip_contents: bool = true#
var connection_lines_antialiased: bool = true#
If true, the lines between nodes will use antialiasing.
var connection_lines_curvature: float = 0.5#
The curvature of the lines between the nodes. 0 results in straight lines.
var connection_lines_thickness: float = 4.0#
The thickness of the lines between the nodes.
var connections: Dictionary[] = []#
The connections between GraphNodes.
A connection is represented as a Dictionary in the form of:
{
from_node: StringName,
from_port: int,
to_node: StringName,
to_port: int,
keep_alive: bool
}Connections with keep_alive set to false may be deleted automatically if invalid during a redraw.
var focus_mode = FOCUS_ALL#
var grid_pattern = GRID_PATTERN_LINES#
The pattern used for drawing the grid.
var minimap_enabled: bool = true#
If true, the minimap is visible.
var minimap_opacity: float = 0.65#
The opacity of the minimap rectangle.
var minimap_size: Vector2 = Vector2(240, 160)#
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.
var panning_scheme = SCROLL_ZOOMS#
Defines the control scheme for panning with mouse wheel.
var right_disconnects: bool = false#
If true, enables disconnection of existing connections in the GraphEdit by dragging the right end.
var scroll_offset: Vector2 = Vector2(0, 0)#
The scroll offset.
var show_arrange_button: bool = true#
If true, the button to automatically arrange graph nodes is visible.
var show_grid: bool = true#
If true, the grid is visible.
var show_grid_buttons: bool = true#
If true, buttons that allow to configure grid and snapping options are visible.
var show_menu: bool = true#
If true, the menu toolbar is visible.
var show_minimap_button: bool = true#
If true, the button to toggle the minimap is visible.
var show_zoom_buttons: bool = true#
If true, buttons that allow to change and reset the zoom level are visible.
var show_zoom_label: bool = false#
If true, the label with the current zoom level is visible. The zoom level is displayed in percents.
var snapping_distance: int = 20#
The snapping distance in pixels, also determines the grid line distance.
var snapping_enabled: bool = true#
If true, enables snapping.
var zoom: float = 1.0#
The current zoom value.
var zoom_max: float = 2.0736#
The upper zoom limit.
var zoom_min: float = 0.232568#
The lower zoom limit.
var zoom_step: float = 1.2#
The step of each zoom level.
Methods #
virtual const func _get_connection_line(to_position: Vector2) -> PackedVector2Array#
Virtual method which can be overridden to customize how connections are drawn.
virtual func _is_in_input_hotzone(mouse_position: Vector2) -> bool#
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:
func _is_in_input_hotzone(in_node, in_port, mouse_position):
var port_size = Vector2(get_theme_constant("port_grab_distance_horizontal"), get_theme_constant("port_grab_distance_vertical"))
var port_pos = in_node.get_position() + in_node.get_input_port_position(in_port) - port_size / 2
var rect = Rect2(port_pos, port_size)
return rect.has_point(mouse_position)virtual func _is_in_output_hotzone(mouse_position: Vector2) -> bool#
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:
func _is_in_output_hotzone(in_node, in_port, mouse_position):
var port_size = Vector2(get_theme_constant("port_grab_distance_horizontal"), get_theme_constant("port_grab_distance_vertical"))
var port_pos = in_node.get_position() + in_node.get_output_port_position(in_port) - port_size / 2
var rect = Rect2(port_pos, port_size)
return rect.has_point(mouse_position)virtual func _is_node_hover_valid(to_port: int) -> bool#
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:
GDScript
func _is_node_hover_valid(from, from_port, to, to_port):
return from != toC#
public override bool _IsNodeHoverValid(StringName fromNode, int fromPort, StringName toNode, int toPort)
{
return fromNode != toNode;
}func add_valid_connection_type(to_type: int) -> void#
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.
func add_valid_left_disconnect_type(type: int) -> void#
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.
func add_valid_right_disconnect_type(type: int) -> void#
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.
func arrange_nodes() -> void#
Rearranges selected nodes in a layout with minimum crossings between connections and uniform horizontal and vertical gap between nodes.
func attach_graph_element_to_frame(frame: StringName) -> void#
Attaches the element GraphElement to the frame GraphFrame.
func clear_connections() -> void#
Removes all connections between nodes.
func connect_node(keep_alive: bool = false) -> intError#
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.
func detach_graph_element_from_frame(element: StringName) -> void#
Detaches the element GraphElement from the GraphFrame it is currently attached to.
func disconnect_node(to_port: int) -> void#
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.
func force_connection_drag_end() -> void#
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.
func get_attached_nodes_of_frame(frame: StringName) -> StringName[]#
Returns an array of node names that are attached to the GraphFrame with the given name.
const func get_closest_connection_at_point(max_distance: float = 4.0) -> Dictionary#
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:
{
from_node: StringName,
from_port: int,
to_node: StringName,
to_port: int,
keep_alive: bool
}For example, getting a connection at a given mouse position can be achieved like this:
var connection = get_closest_connection_at_point(mouse_event.get_position())func get_connection_count(from_port: int) -> int#
Returns the number of connections from from_port of from_node.
const func get_connection_line(to_node: Vector2) -> PackedVector2Array#
Returns the points which would make up a connection between from_node and to_node.
const func get_connections_intersecting_with_rect(rect: Rect2) -> Dictionary[]#
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:
{
from_node: StringName,
from_port: int,
to_node: StringName,
to_port: int,
keep_alive: bool
}func get_element_frame(element: StringName) -> GraphFrame#
Returns the GraphFrame that contains the GraphElement with the given name.
func get_menu_hbox() -> HBoxContainer#
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.
func is_node_connected(to_port: int) -> bool#
Returns true if the from_port of the from_node GraphNode is connected to the to_port of the to_node GraphNode.
const func is_valid_connection_type(to_type: int) -> bool#
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.
func remove_valid_connection_type(to_type: int) -> void#
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.
func remove_valid_left_disconnect_type(type: int) -> void#
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.
func remove_valid_right_disconnect_type(type: int) -> void#
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.
func set_connection_activity(amount: float) -> void#
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.
func set_selected(node: Node) -> void#
Sets the specified node as the one selected.
Annotations #
Constants #
const SCROLL_ZOOMS = 0 enum PanningScheme#
Mouse Wheel will zoom, Ctrl + Mouse Wheel will move the view.
const SCROLL_PANS = 1 enum PanningScheme#
Mouse Wheel will move the view, Ctrl + Mouse Wheel will zoom.
const GRID_PATTERN_LINES = 0 enum GridPattern#
Draw the grid using solid lines.
const GRID_PATTERN_DOTS = 1 enum GridPattern#
Draw the grid using dots.
Constructors #
Enums #
PanningScheme#
enum PanningScheme {
SCROLL_ZOOMS = 0,
SCROLL_PANS = 1,
}GridPattern#
enum GridPattern {
GRID_PATTERN_LINES = 0,
GRID_PATTERN_DOTS = 1,
} Operators #
Signals #
signal begin_node_move()#
Emitted at the beginning of a GraphElement's movement.
signal connection_drag_ended()#
Emitted at the end of a connection drag.
signal connection_drag_started(is_output: bool)#
Emitted at the beginning of a connection drag.
signal connection_from_empty(release_position: Vector2)#
Emitted when user drags a connection from an input port into the empty space of the graph.
signal connection_request(to_port: int)#
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.
signal connection_to_empty(release_position: Vector2)#
Emitted when user drags a connection from an output port into the empty space of the graph.
signal copy_nodes_request()#
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.
signal cut_nodes_request()#
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.
signal delete_nodes_request(nodes: StringName[])#
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.
signal disconnection_request(to_port: int)#
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.
signal duplicate_nodes_request()#
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.
signal end_node_move()#
Emitted at the end of a GraphElement's movement.
signal frame_rect_changed(new_rect: Rect2)#
Emitted when the GraphFrame frame is resized to new_rect.
signal graph_elements_linked_to_frame_request(frame: StringName)#
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.
signal node_deselected(node: Node)#
Emitted when the given GraphElement node is deselected.
signal node_selected(node: Node)#
Emitted when the given GraphElement node is selected.
signal paste_nodes_request()#
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.
signal popup_request(at_position: Vector2)#
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.
signal scroll_offset_changed(offset: Vector2)#
Emitted when the scroll offset is changed by the user. It will not be emitted when changed in code.
Theme Items #
self["theme_override_colors/activity"] = Color(1, 1, 1, 1) as Color#
Color the connection line is interpolated to based on the activity value of a connection (see set_connection_activity).
self["theme_override_colors/connection_hover_tint_color"] = Color(0, 0, 0, 0.3) as Color#
Color which is blended with the connection line when the mouse is hovering over it.
self["theme_override_colors/connection_rim_color"] = Color(0.1, 0.1, 0.1, 0.6) as Color#
Color of the rim around each connection line used for making intersecting lines more distinguishable.
self["theme_override_colors/connection_valid_target_tint_color"] = Color(1, 1, 1, 0.4) as Color#
Color which is blended with the connection line when the currently dragged connection is hovering over a valid target port.
self["theme_override_colors/grid_major"] = Color(1, 1, 1, 0.2) as Color#
Color of major grid lines/dots.
self["theme_override_colors/grid_minor"] = Color(1, 1, 1, 0.05) as Color#
Color of minor grid lines/dots.
self["theme_override_colors/selection_fill"] = Color(1, 1, 1, 0.3) as Color#
The fill color of the selection rectangle.
self["theme_override_colors/selection_stroke"] = Color(1, 1, 1, 0.8) as Color#
The outline color of the selection rectangle.
self["theme_override_constants/connection_hover_thickness"] = 0 as int#
Widen the line of the connection when the mouse is hovering over it by a percentage factor. A value of 0 disables the highlight. A value of 100 doubles the line width.
self["theme_override_constants/port_hotzone_inner_extent"] = 22 as int#
The horizontal range within which a port can be grabbed (inner side).
self["theme_override_constants/port_hotzone_outer_extent"] = 26 as int#
The horizontal range within which a port can be grabbed (outer side).
self["theme_override_icons/grid_toggle"] = icon as Texture2D#
The icon for the grid toggle button.
self["theme_override_icons/layout"] = icon as Texture2D#
The icon for the layout button for auto-arranging the graph.
self["theme_override_icons/minimap_toggle"] = icon as Texture2D#
The icon for the minimap toggle button.
self["theme_override_icons/snapping_toggle"] = icon as Texture2D#
The icon for the snapping toggle button.
self["theme_override_icons/zoom_in"] = icon as Texture2D#
The icon for the zoom in button.
self["theme_override_icons/zoom_out"] = icon as Texture2D#
The icon for the zoom out button.
self["theme_override_icons/zoom_reset"] = icon as Texture2D#
The icon for the zoom reset button.
self["theme_override_styles/menu_panel"] = style as StyleBox#
self["theme_override_styles/panel"] = style as StyleBox#
The background drawn under the grid.