How to access properties of a Node in the current scene from plugin

Hi All,

I am writing a plugin and what I want is to display the content of a property for the current node.

I have created a ItemStateManager that has a property item_states and attached to the scen as a Node.

extends Node
class_name ItemStateManager

var item_states: Dictionary = {}  # Stores item locations and states
var branch_conditions: Callable = Callable()  # Scene-specific branching logic

# Registers an item at a specific location with optional state
func register_item(item_name: String, location: String, state: String = ""):
	item_states[item_name] = {"location": location, "state": state}

# Updates an item's location and state
func update_item(item_name: String, new_location: String, new_state: String = ""):
	if item_states.has(item_name):
		item_states[item_name]["location"] = new_location
		if new_state:
			item_states[item_name]["state"] = new_state
	else:
		register_item(item_name, new_location, new_state)

# Retrieves the item's location
func get_item_location(item_name: String) -> String:
	return item_states.get(item_name, {}).get("location", "")

# Retrieves the item's state
func get_item_state(item_name: String) -> String:
	return item_states.get(item_name, {}).get("state", "")

# Sets branching logic dynamically per scene
func set_branching_logic(logic_callable: Callable):
	branch_conditions = logic_callable

# Determines branching dynamically using scene-supplied logic
func check_branching_conditions(action: Action):
	if branch_conditions.is_valid():
		return branch_conditions.call(action)
	return action.next_actions[0]  # Default to first action if no logic supplied

Then in my plugin I am trying to access and display it in a tree like this:

@tool
extends Control

@onready var item_tree: Tree = $MainContainer/ItemTree
@onready var refresh_button: Button = $MainContainer/RefreshButton

func _ready():
	if not Engine.is_editor_hint():
		return  # Ensure this only runs in the editor

	if refresh_button:
		refresh_button.pressed.connect(_refresh_tree)

	set_process(true)
	_refresh_tree()

func _process(delta):
	if not Engine.is_editor_hint():
		_refresh_tree()

func _refresh_tree():
	var item_manager = _find_item_state_manager()
	
	if not item_manager:
		print("⚠ Error: ItemStateManager not found!")
		return

	item_manager = item_manager as ItemStateManager
	
	if not item_manager:
		print("⚠ Error: Found node is not an ItemStateManager!")
		return

	if not item_manager.has_method("get_item_location"):
		print("⚠ Error: ItemStateManager does not have the expected functions!")
		return

	var item_states = item_manager.item_states if item_manager.has_method("register_item") else {}

	print("✅ Debug - Found item_states:", item_states)

	if item_states.is_empty():
		print("⚠ Error: ItemStateManager exists but has no items.")
		return

	item_tree.clear()

	var root = item_tree.create_item()

	item_tree.set_columns(3)
	item_tree.set_column_titles_visible(true)
	item_tree.set_column_title(0, "Item")
	item_tree.set_column_title(1, "Location")
	item_tree.set_column_title(2, "State")

	for item_name in item_states.keys():
		var item_info = item_states[item_name]
		var tree_item = item_tree.create_item(root)

		tree_item.set_text(0, item_name)
		tree_item.set_text(1, item_info.get("location", "Unknown"))
		tree_item.set_text(2, item_info.get("state", "Unknown"))

func _find_item_state_manager():
	if Engine.is_editor_hint():
		var edited_scene = EditorInterface.get_edited_scene_root()
		if edited_scene:
			return edited_scene.find_child("ItemStateManager", true, false)
	else:
		var running_scene = get_tree().current_scene
		if running_scene:
			return running_scene.find_child("ItemStateManager", true, false)

	return null

Doesn’t matter what I’ve tried it seems like there is no way i can access the item_states from the plugin.

 ERROR: res://addons/item_state_visualizer/item_state_panel.gd:40 - Invalid access to property or key 'item_states' on a base object of type 'Node (ItemStateManager)'.

Also it seems like the scene and the plugin are not seeing the same ItemStateManager when I tried to print them.

ItemStateManager:<Node#30903633259> (From the scene)
{ "cup": { "location": "cabinet", "state": "clean" }, "diary": { "location": "desk", "state": "closed" } }
  ERROR: res://addons/item_state_visualizer/item_state_panel.gd:39 - Invalid access to property or key 'item_states' on a base object of type 'Node (ItemStateManager)'.
ItemStateManager:<Node#3283418700104> (From the plugin)

Any idea on this is appreciated, thanks

You can’t access non-exported properties from a non-tool script. You have 2 options:

  • Export the variable. You can use @export_storage so it won’t show in the inspector.
  • Make your ItemStateManager a tool script. You won’t need to export the variable then.

The editor scene and the running scene are different. If you need to communicate between the running game and the editor you’ll need to use and EditorDebuggerPlugin

1 Like

Thank you so much for your reply, I’ve rewrote the plugin using EditorDebuggerPlugin and everything works in the debugger panel and I am able to send messages to get the states.