godot: EditorExportPlugin raises error everytime you run the game with F5 because of "abstract native class"
Godot version
4.0 rc2
System information
Manjaro Linux using i3, Foward+
Issue description
I’ve added an ExportPlugin to my addon and everytime I run the game in the editor I know get this error:
SCRIPT ERROR: Parse Error: Class "eh_UtilitiesExportPlugin" cannot be constructed as it is based on abstract native class "EditorExportPlugin".
I even tried to guard it with an Engine.is_editor_hint()
call but it doesn’t work, I still get the same error even though line 54 shouldn’t be executing:
Weirdly enough, this guard works fine in other parts of the project, but fails here.
Steps to reproduce
Just create a script that extends EditorExportPlugin
, and try to create an instance of it in an EditorPlugin
script
Minimal reproduction project
See “Steps to Reproduce”
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 3
- Comments: 18 (8 by maintainers)
Commits related to this issue
- Fix gdscript analyzer error when instantiating EditorPlugins. Editor code is not instantiable outside of the editor (https://github.com/godotengine/godot/blob/1d14c054a12dacdc193b589e4afb0ef319ee2aae... — committed to baptr/godot by baptr a year ago
- WIP: Fix gdscript analyzer error when instantiating EditorPlugins. Editor code is not instantiable outside of the editor (https://github.com/godotengine/godot/blob/1d14c054a12dacdc193b589e4afb0ef319e... — committed to baptr/godot by baptr a year ago
- Fix gdscript analyzer error when instantiating EditorPlugins. Editor code is not instantiable outside of the editor (https://github.com/godotengine/godot/blob/1d14c054a12dacdc193b589e4afb0ef319ee2aae... — committed to baptr/godot by baptr a year ago
- Fix gdscript analyzer error when instantiating EditorPlugins. Editor code is not instantiable outside of the editor (https://github.com/godotengine/godot/blob/1d14c054a12dacdc193b589e4afb0ef319ee2aae... — committed to baptr/godot by baptr a year ago
- Fix gdscript analyzer error when instantiating EditorPlugins. Editor code is not instantiable outside of the editor (https://github.com/godotengine/godot/blob/1d14c054a12dacdc193b589e4afb0ef319ee2aae... — committed to baptr/godot by baptr a year ago
In my project, I’m not actually accessing the Editor-only classes during game runtime. However, my scripts are still loaded/parsed, and the compiler complains about it. The script code is never executed.
At least, this is what I believe to be happening, based on the fact that casting the Editor-only class to a Variant fixes the compile error, and there are no further errors during runtime.
Meanwhile, a workaround:
Casting the
EditorExportPlugin
-derived class to aVariant
seems to trick the compiler:Presumably this would also work with other classes that might have this issue.
Right, it’s registered as a normal full class: https://github.com/godotengine/godot/blob/2ec0da1a75a066fe88986fc6ceda22fbabf7eedd/editor/register_editor_types.cpp#L133
But the recently added gdscript analyzer check which tries to determine if a parent class is abstract, instead only checks if it can be instantiated right now. The fact that editor types can’t be instantiated when running the project leads to the analyzer incorrectly interpreting them as being “abstract”.
Ah: https://github.com/godotengine/godot/blob/1d14c054a12dacdc193b589e4afb0ef319ee2aae/core/object/class_db.cpp#L363-L370
You can’t instantiate any editor code while running.