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

Improve handling of custom types #58617

Merged
merged 1 commit into from
Sep 7, 2022

Conversation

KoBeWi
Copy link
Member

@KoBeWi KoBeWi commented Feb 28, 2022

Originally started as a fix for #35205, but I got a bit carried away.

The PR improves how custom types (i.e. types added with EditorPlugin.add_custom_type()) are handled throughout editor:

  • added some helper methods to check if custom type exists
  • fixed a bug where custom types weren't properly saved in history by create dialog (fixes Custom types can't be favorited #35205)
  • custom types will now display their icon in inspector categories
    It looks bad with #57286 though:
    image
    but that's another issue to be fixed separately.
  • custom types are now recognized by script create dialog. However, since they are not a real types, the script path will be implicitly inserted instead

So about the "they are not a real types" part, I discovered that while going through code. Custom types are supposed to be a helper to add a node with a specific script. They also have a gray icon in scene tree dock, unlike class_name types:
image
(this should be probably made consistent)
They aren't supposed to be real classes. They don't even register their name anywhere, aside from some internal map in EditorData. I added a mention in the docs that clarifies it a bit.

Their advantage is that you can enable/disable a plugin and the type will be added/removed from editor, but none of your scripts will break, because the type is never referenced by name. Thanks to that they also don't clutter global scope with more class names.
The disadvantage is that you can't create them from script using their name. Also users probably don't expect them to work this way; I bet there are some open issues that are invalid for this reason.

Anyways, this rambling isn't really related to this PR. There were just voices that we should consider removing custom types in 4.0, so the above text could be a good reference for a proposal.

@KoBeWi KoBeWi added this to the 4.0 milestone Feb 28, 2022
@KoBeWi KoBeWi requested a review from a team as a code owner February 28, 2022 01:16
@mhilbrunner mhilbrunner requested a review from YuriSizov August 18, 2022 16:02
@YuriSizov
Copy link
Contributor

I think this looks fine, besides a small note above. We didn't settle on removing this, so I guess we aren't. Didn't test it, would appreciate a rebase.

Also maybe @willnationsdev can give it a check? It touches on some stuff related to his work.

Copy link
Contributor

@YuriSizov YuriSizov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, and the mentioned features work.

One minor problem I've noticed is that the icon for the node, when creating a scene from a custom type, is not displayed correctly initially, but fixes itself after the scene is reloaded.

@akien-mga akien-mga merged commit 2b6e043 into godotengine:master Sep 7, 2022
@KoBeWi KoBeWi deleted the custom_something branch September 7, 2022 16:27
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom types can't be favorited
3 participants