Teleport

Get access to nodes anywhere in the project

First, we define a global object, Teleport that will allow us get reference to other nodes registered with it.

Teleport.gd

extends Node

var nodes = {}

func get(node_name: String) -> Node:
	var config = nodes[node_name]
	return config.root.get_node(config.path)

func add(root: Node, exports: Dictionary) -> void:
	for node_name in exports:
		if nodes.has(node_name):
			push_error("Teleport already has node with name '" + node_name + "', skipping...")
			continue
		var node_path = exports[node_name]
		nodes[node_name] = {
			root = root,
			path = node_path,
		}

Then we create a dynamic way to have exports in a node. This is a SmartNode2D class

SmartNode2D.gd

Example

Declare, set nodes in UI

Then use them

Last updated