7.13 No new global access paths
Rule: §7.13 in the code standards; the existing holders are in B2.
Why
A global access path lets any script reach a collaborator without the collaborator appearing in its signature: an autoload, a static var that holds another module’s instance or state other modules share, or a lookup through the tree, a group or Engine meta (get_node("/root/…"), get_tree().get_nodes_in_group(…), Engine.get_meta(…)). Nothing at the call site says the script depends on it, and the script only works once something else has filled the global first, an order no signature records. Passing the collaborator in (7.11) makes both visible.
A set_*/clear_* pair on an instance is injection (7.11). A static setter that fills a static var is still a global holder, even when the root calls it and undoes it in teardown: any script that preloads the module can read the value. The holders that exist are listed in B2.
Good
The collaborator arrives as an argument and lives in the user’s own instance; nothing outside the composer can reach it (addons/godot_mcp_toolkit/core/plugin_composer.gd:66, compose):
var debug_bridge := DebugBridge.new(session_tracker)
Bad
A lookup that reaches the server through Engine meta, so the dependency appears in no signature and the call fails whenever it runs before the composer has stored the server:
var server: Node = Engine.get_meta("mcp_server")
This shape is not in the tree. The existing static holder it most resembles is EditorAccess, which the plugin fills at start-up and every editor-side script can read (addons/godot_mcp_toolkit/core/editor_access.gd:15, :19-20; filled at plugin.gd:38):
static var _plugin: EditorPlugin
static func set_plugin(plugin: EditorPlugin) -> void:
_plugin = plugin
It is listed in B2 and stays; a new collaborator does not join it.
Source
- Nystrom, Game Programming Patterns, “Singleton” and “Service Locator” (a global hides coupling; pass the object in where you can): https://gameprogrammingpatterns.com/singleton.html, https://gameprogrammingpatterns.com/service-locator.html
- Seemann, the service-locator anti-pattern: https://blog.ploeh.dk/2010/02/03/ServiceLocatorisanAnti-Pattern
- Godot, autoloads versus regular nodes (global state, global access, global allocation): https://docs.godotengine.org/en/stable/tutorials/best_practices/autoloads_versus_regular_nodes.html