-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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
Scripts fail to load with a parse error on exported projects if it uses editor classes #91713
Comments
IMO this is the way. You can do this indirectly for partial safety: func _ready():
if Engine.is_editor_hint():
var editor = load("res://some_script_using_editor_interface.gd")
editor.connect_reimported(_on_resource_reimport) where the loaded script does what you quoted above. It can provide a type-safe interface with only the script in the scene doing unsafe calls. |
This will not work with static typing, only with dynamic typing (if you use As a workaround, I would suggest my plugin gdscript-preprocessor (sorry for the self-promotion). We could try to solve this out of the box by adding an exception for editor classes when analyzing/compiling the script. However, at runtime this should still give an error if execution reaches this point. So I think that this is a rather complex solution, which also adds inconsistency. |
No I mean this (for func connect_reimported(callback: Callable):
var editor_filesystem := EditorInterface.get_resource_filesystem()
if not editor_filesystem.resources_reimported.is_connected(callback):
editor_filesystem.resources_reimported.connect(callback) This code is type-safe, but it won't cause problems, because it's loaded using |
Also, this isn't mentioned in the documentation and works when running from the editor leaving it to be discovery possible late in development only after exporting. |
Also related: #56798 (I just remembered) |
Related: #86013 |
… exported build. Even though the script doesn't do anything at runtime, it still exists, and its use of the EditorInterface class causes a load failure in Godot builds that don't have editor classes. godotengine/godot#91713
… exported build. Even though the script doesn't do anything at runtime, it still exists, and its use of the EditorInterface class causes a load failure in Godot builds that don't have editor classes. godotengine/godot#91713
Got this happening with me on exported games on 4.3. The first workaround suggested by @ydeltastar , worked so far. |
Just discovered this. I have tool scripts in my game that do stuff in the editor, and already filter their actions based on the editor hint. We made EditorInterface static #75694 to make tool scripts easier. But to break an exported game because a script mentions, but doesn't use the class isn't good. What about replacing editor classes with dummy classes? How about recognizing a code block that starts with What about giving us preprocessor defines that demark editor only code, to replace |
Taking Python as an example, the following will execute without errors when evaluating to false even if print("Input anything besides 'editor' to succeeded")
x = input()
if "editor" in x:
print(EditorInterface.get_stuff())
else:
print("it works") Python probably replaces it with a placeholder or an error opcode. No need for workarounds on the user side if the parser step is less strict during compilation. |
Python is a purely dynamic language, type hints are completely optional. Therefore, any non-existent identifiers do not cause a runtime error until execution reaches them. GDScript combines the qualities of both dynamic and static typing. GDScript uses type hints and implicitly inferred types for static analysis and optimizations, and reports non-existent identifiers (but this does not apply to attribute/index access). Changing this behavior may be undesirable because it helps users find errors faster. You can use But I agree that this is a pretty important point that can hinder users who want to have different code for different platforms, operating systems, distribution stores and other types of engine builds and custom feature tags. I think there are the following options to solve this problem:
|
This bug is hard to uncover with inherited classes. Take this example: @tool
extends Node
class_name BaseTool
func editor_selection():
EditorInterface.get_selection() @tool
extends BaseTool
class_name CustomTool
func _ready():
print("CustomTool is working!"); If you create a scene with a single
There's no mention of |
Tested versions
v4.3.dev.custom_build [2042420]
System information
Windows 11
Issue description
Tool scripts using an editor class such as
EditorInterface
will fail to load with a parse error only on exported projects.Output of debug template console wrapper:
Well, it makes sense. Editor classes aren't included in distribution builds but there is no conditional compiling in GDScript so tool scripts with game and editor code can't be used at all in a project.
Workarounds:
var editor_interface = Engine.get_singleton("EditorInterface")
.godot.exe
.Steps to reproduce
Export a project that uses the script above with a debug template and run the
.console.exe
version.Minimal reproduction project (MRP)
N/A
The text was updated successfully, but these errors were encountered: