Plugin mutable access to Arrays in SceneTree

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By regexp*

I’m building a editor plugin for connecting nodes (consumers and producers) to one another using a graph editor. I have a Orchestrator object that keeps track of all nodes, and creates a pool for each connection. Each node keeps track of which index in the pool array it consumes and produces into. The architecture in itself can be handled in the normal inspector, but with many nodes it gets complicated. When I add a connection in the graph editor, I want to edit the mentioned indices of the nodes involved.

The problem lies in modifying properties carried by nodes in the SceneTree from the plugin.

I have gotten stuck as that doesn’t seem possible. If i try to refer to a nodes index, i get:

resourceGrapher.gd:77 - Invalid get index 'net_ids'

I have also tried using @export on the net_id, but to no avail.

Array is in read-only state

I have tried exporting an integer and setting it, and that works. So I think this relates to arrays specifically.

Code from other nodes doesn’t run in the editor. Your access to other
nodes is limited. You can access the tree and nodes, and their default
properties, but you can’t access user variables. If you want to do so,
other nodes have to run in the editor too. AutoLoad nodes cannot be
accessed in the editor at all.

This quote from the docs seems reasonable, and i understand why that wouldn’t be optimal. But how would i work around this? I thought about the editor creating some resource with can be imported into the orchestrator, but I’m not sure this is the right path.

Here follows a little example of what I’m trying to do:

# plugin.gd
...
def on_node_registered(sysnode):
    sysnode.net_ids.resize(12)

def on_node_edit_connection_request(a, a_from, b, b_to):
    var node_from = get_sysnode(a)
    var node_to = get_sysnode(b)
    const new_ind = create_new_id()
    node_from.net_ids[a_from] = new_ind
    node_to.net_ids[b_to] = new_ind

And the nodes themselves.

# system_node.gd
@export var net_ids: Array[int] = []