Improve handling of custom types #58617
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:It looks bad with #57286 though:
but that's another issue to be fixed separately.
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:(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.