Making a non-orientated graph, can I make a Tool or anything that ensures that neighbours are both sides?

Godot Version

4.6

Question

Hello everyone. I want to represent a map, with points of interests linked together, like a graph like that :

To represent a neighbour, I have made an array of enums, where each enum is the ID of the vertex (and is used for other parts of the game)


Can I make something that runs in the engine that automatically adds and removes when modified ? Furthermore, can it be done considering the node already have a script (C#) attached to it ? Or should I do it manually ?

Thank you in advance :blush:

You can use a @tool script and use CanvasItem._draw() to draw whatever you need.

Quick example:

@tool
extends Sprite2D


@export var links: Array[Sprite2D]:
	set(value):
		links = value
		queue_redraw()


func _draw() -> void:
	for link in links:
		draw_line(Vector2.ZERO, to_local(link.global_position), Color.RED)

It’s not only to draw, it’s also important gameplay wise