Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for adding/removing editor plugins #1114

Merged
merged 1 commit into from
May 26, 2023

Conversation

dsnopek
Copy link
Collaborator

@dsnopek dsnopek commented May 17, 2023

This depends on godotengine/godot#77010

It allows adding or removing editor plugins from GDExtension, in a way that's very similar to adding them in a Godot module.

Here's some example code from a test GDExtension:

void initialize_summator_types(ModuleInitializationLevel p_level)
{
	if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
		ClassDB::register_class<Summator>();
	}

	if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
		ClassDB::register_class<MyEditorPlugin>();
		EditorPlugins::add_by_type<MyEditorPlugin>();
	}
}

void uninitialize_summator_types(ModuleInitializationLevel p_level) {
	if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) {
		EditorPlugins::remove_by_type<MyEditorPlugin>();
	}
}

Please let me know what you think!

Fixes #640

@dsnopek dsnopek added the enhancement This is an enhancement on the current functionality label May 17, 2023
@dsnopek dsnopek requested a review from a team as a code owner May 17, 2023 03:04
@akien-mga akien-mga merged commit 2078c00 into godotengine:master May 26, 2023
@akien-mga
Copy link
Member

Thanks!

@Zylann
Copy link
Collaborator

Zylann commented Jun 3, 2023

I wonder why classes dont need to be unregistered (they are done automatically) yet plugins have to be unregistered manually?

@dsnopek
Copy link
Collaborator Author

dsnopek commented Jun 7, 2023

@Zylann:

I wonder why classes dont need to be unregistered (they are done automatically) yet plugins have to be unregistered manually?

That's a good question!

It looks like ClassDB on the godot-cpp side is keeping track of the classes we register, and then GDExtensionBinding::deinitialize_level() is calling ClassDB::deinitialize() which is removing them.

We should be able to do the same thing for editor plugins! EditorPlugins in godot-cpp could keep track of what we've registered, and we could add a EditorPlugins::deinitialize() that removes them, and call it in GDExtensionBinding::deinitialize_level().

I'll add it to my TODO list! (Unless you want to make the PR for this?)

@Zylann
Copy link
Collaborator

Zylann commented Jun 7, 2023

Unless you want to make the PR for this?

Too busy on other things atm.

Thanks for adding this feature to GodotCpp, it was sorely missed :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an enhancement on the current functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GDExtension] EditorPlugin Tool
3 participants