Open m6502 opened 4 years ago
Honestly yeah, this is not a bug. You should rebuild your code to actually use an EditorPlugin for this. And then invoke that plugin, instead of instancing a new object whenever you need the editor for something.
A good old case of "you're doing it wrong".
The EditorPlugin class could mention it's only intended to be extended and registered as a plugin in the editor. Moving to the docs repo.
I think this is basically the same issue: https://github.com/godotengine/godot/issues/41196
In this case, though, I'm using GDScript instead of C# and there's no way to enclose the offending code in preprocessor directives.
Godot version:
I'm using the official 3.2.2 Godot build.
OS/device including version:
Not related to any specific backend.
Issue description:
One of my scripts contains game functionality plus tool functionality. When in tool mode, at init, I need to create an instance of EditorPlugin so I can reach the editor interface. The code is inside an if statement checking for the editor:
Works as expected and the resulting editor interface is only ever used when in tool mode and always after checking for the editor presence. The problem though is when trying to export the game. EditorPlugin doesn't exist then, and the resulting build doesn't work because the script can't be loaded. Here is an screenshot of the output log with Windows, but this happens with html5 and I suppose any other platform too:
Steps to reproduce:
Try to include the above code in a project or just use the enclosed test project.
Minimal reproduction project:
EditorPluginTroubles.zip
This project only shows one sprite that is marked as not visible in the project tree, but the script makes it visible at _ready(). If the script fails then the sprite remains invisible and only the background is shown.
So this really isn't a bug per se, and I was hesitant about opening an issue or a proposal, but my gut instinct tells me there's something not quite right in this situation that could be improved. If there's a an alternate way to get the editor interface I'm interested in knowing too :-)