Communication between Autoload and EditorPlugin

Godot Version

4.4

Question

I set up a plugin like this:

func _enter_tree():
	add_autoload_singleton("MyAutoload", "res://addons/my_addon/my_autoload.tscn")
	
	editor_panel = preload("res://addons/my_addon/editor_panel.tscn").instantiate()
	add_control_to_bottom_panel(editor_panel, "My Panel")

But how can these two communicate? I basically want MyAutoload-functions to be accessible from anywhere. And these functions have to communicate with the editor panel to generate some output in it. Somehow I can’t get them to interact with each other.

You can create a variable in autoload and initialize it with the panel here:

# autoload
var plugin_panel: Control

func get_name() -> String: # for example
    return "MyAutoload"
# plugin script
func _enter_tree():
	editor_panel = preload("res://addons/my_addon/editor_panel.tscn").instantiate()
	add_control_to_bottom_panel(editor_panel, "My Panel")

    add_autoload_singleton("MyAutoload", "res://addons/my_addon/my_autoload.tscn") # Why this isn't .gd?
    MyAutoload.plugin_panel = editor_panel
# panel
MyAutoload.get_name() # Access example

If you only want to monitor some numeric information you can use Performance.add_custom_monitor() for that.

If you want to be able to communicate between your game and editor then you’ll need to use EngineDebugger to send and receive information from your game to the editor and write a EditorDebuggerPlugin to capture those messages and send back commands from the editor to your game. Here’s an example Godot 4.x example of how to launch multiple instances and tile them by using an editor debugger plugin to communicate with each instance · GitHub

Thanks for the replies.

@Mahan: I tried that, but when I call “MyAutoload.plugin_panel.something()” I get Null for the plugin_panel.

@mrcdk: I thought instead of printing my debug information in the game itself I could put it inside the editor to have everything a bit more organized. Somehow this seems to be more complicated than I thought. :slight_smile: