Editor plugins

Using EditorPlugin types is very similar to the process used when writing plugins in GDScript. Unlike GDScript plugins, godot-rust plugins are registered automatically and cannot be enabled/disabled in the Project Settings plugins pane.

Plugins written in GDScript are automatically disabled if they have a code error, but because Rust is a compiled language, you cannot introduce compile-time errors.

Creating an EditorPlugin

#![allow(unused)]
fn main() {
#[derive(GodotClass)]
#[class(tool, init, editor_plugin, base=EditorPlugin)]
struct MyEditorPlugin {
    base: Base<EditorPlugin>,
}

#[godot_api]
impl IEditorPlugin for MyEditorPlugin {
    fn enter_tree(&mut self) {
        // Perform typical plugin operations here.
    }

    fn exit_tree(&mut self) {
        // Perform typical plugin operations here.
    }
}
}

Since this is an EditorPlugin, it will be automatically added to the scene tree root. This means it can access the scene tree at runtime. Additionally, it is safe to access the EditorInterface singleton through this node, which allows adding different GUI elements to the editor directly. This can be helpful if you have an advanced GUI you want to implement.