Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ChristophtTheSchmidt |
Hello
I want to create a Plugin that adds a Control to the engine layout. This works fine. But I cannot pass a reference to EditorPlugin script that adds these Controls. I need to pass that reference because I want the Controls to be able to access functions that only a EditorPlugin can run ( get_editor_interface e.g.).
Minimal project to explain my problem:
The Control added by the plugin is a CenterContainer with a Button as a Child.
When the Button is clicked it is supposed to print the Plugin variable to the standardoutput.
The CenterContainer has the following script:
extends Control
var Plugin
func _ready() -> void:
print("control ready")
func _on_button_button_up() -> void:
print("plugin is: ",Plugin)
The Plugin has the following script:
@tool
extends EditorPlugin
@onready var PluginControl
func _enter_tree() -> void:
PluginControl = load("res://addons/LevelEditor/PluginControl.tscn").instantiate()
add_child(PluginControl)
PluginControl.Plugin = self
func _exit_tree() -> void:
PluginControl.free()
Neither does the ready func in Control print nor can the EditorPlugin assign self to the var Plugin in Control. It does not make a difference if it is a @onready var instead of var or if the EditorPlugin tries to assign it in its _ready or init or enter_tree (as shown above).
How do you people make the EditorPlugin script interact with its Controls?
I appreciate you help Thanks!