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"