0 votes

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 ( geteditorinterface 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:

extends EditorPlugin

@onready var PluginControl

func _enter_tree() -> void:
    PluginControl = load("res://addons/LevelEditor/PluginControl.tscn").instantiate()
    PluginControl.Plugin = self

func _exit_tree() -> void:

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 entertree (as shown above).

How do you people make the EditorPlugin script interact with its Controls?
I appreciate you help :) Thanks!

Godot version 4.0 beta
in Engine by (16 points)

1 Answer

+1 vote

i think the problem is that the control does not go into ready state because it isnt initialized by a sceneTree.
i think you want your control to be added to the editor!?
You have to add it via the EditorPlugin to the editor with a proper function call ....

addcontroltobottompanel(panel,"the panels name")

then there should be a ready event and the plugin should be accessable.

by (4,068 points)

Thank you :)
I solved the problem in a different way: I had forgotten the @tool at the top of the Control script, adding it solved everything!

For some reason using add-child(Control) inside EditorPlugin is possible..
You dont have to use add-control-to-bottompanel(). For me this is strange because there is no documentation out there telling you where the EditorPlugin script is actually positioned. Maybe calling add-child inside it makes the Control just a child of the overall Editor Control..

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.