How do I pass some data from the plugin to it's main scene

Godot Version

V4

Question

I would like to pass/store some data from the plugin.gd, to it’s main panel scene (such as name of plugin. Is there anyway to do that directly without using autoload global or using the file system such as cfg?

Here is my plugin initialization code below. In _enter_tree() it instances a scene and adds it to the EditorInterface screen. Does my MainPanel Instance have access to any data in the plugin.gd? Currently I am using environment variables, but I would prefer something cleaner.

@tool
# plugin.gd
extends EditorPlugin

var MainPanel:PackedScene 
var main_panel_instance:Control
var plugin_descriptive_name
var base_dir

func _init():
	base_dir=get_script().get_path().get_base_dir()
	var conf = ConfigFile.new()
	conf.load(base_dir+"/plugin.cfg")
	plugin_descriptive_name = conf.get_value("plugin", "name")
	MainPanel = load(base_dir+"/main_panel.tscn")
	print("\n\nInitialized!!: ",plugin_descriptive_name)

func _enter_tree():
	main_panel_instance = MainPanel.instantiate()
	# Add the main panel to the editor's main viewport.
	EditorInterface.get_editor_main_screen().add_child(main_panel_instance)
	_make_visible(false)

func _exit_tree():
	if main_panel_instance:
		main_panel_instance.queue_free()

func _has_main_screen():
	return true

func _make_visible(visible):
	if main_panel_instance:
		main_panel_instance.visible = visible

func _get_plugin_name():
	return plugin_descriptive_name

func _get_plugin_icon():
	# Must return some kind of Texture2D for the icon.
	return get_editor_interface().get_base_control().get_theme_icon("Node", "EditorIcons")

plugin.cfg

[plugin]

name="My Plugin"
description="Demonstrates how to make a main screen plugin."
author="wyatt"
version="1.0"
script="plugin.gd"

If I’m understanding your question correctly, you’ve pretty much already done it.

Your main_panel_instance IS the main panel of your scene, so you could just pass the data into that in your _enter_tree method, as long as it has a variable ready for it. Maybe to make it more extendable you could pass the ConfigFile that loads the cfg file and just use that? Making your conf a property instead of a variable in instance of course.

Does that make sense? Am I misreading the situation?

1 Like

I did not realize it was as simple as that. Thank you!

1 Like