Always get empty data when trying to get data in EditorPlugin script

Godot Version

4.4

Question

I am making a Object Pool Debug Panel Plugin, and ran into some issue.

@tool
extends EditorPlugin

var panel

func _enter_tree() -> void:
	add_autoload_singleton("ObjPoolData","res://addons/ObjectPooling/PoolData.gd")
	var btnConnect:Button = panel.get_node("ScrollContainer/VBoxContainer/HBoxContainer/Connect")
	btnConnect.pressed.connect(_on_press_connect)
	
func _on_press_connect():
	print(ObjPoolData.PoolDic)

Here are the plugin code
And the res://addons/ObjectPooling/PoolData.gd is

@tool
extends Node

@export var PoolDic:Dictionary = {}

func _ready() -> void:
	for node in get_tree().get_nodes_in_group("ObjPool"):
		node.pool_count_change.connect(
			func():
				ObjPoolData.PoolDic[node.name] = {
				"currentAmount":node.currentAmount,
				"objInScene":node.objInScene
			})

Ignore other stuff, every time an object spawned, the dictionary changed.
The dictionary works fine when I trying to print it in my game scene, but when I try to print it in my Editor Plugin script, it always get an empty dictionary.
Did I do something wrong, or godot’s editor plugin can’t have access to the auto load script.

Autoloads are only available in game. They are just nodes that are added to the root node when running the game. The editor does not do this.

If you want to communicate between your game and the editor then you need to use an EditorDebuggerPlugin and the EngineDebugger class. There’s an example in the documentation of these classes.

1 Like