-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
EditorPlugin singleton doesn't work #68685
Comments
The documentation states that the EditorInterface should not be instanced and that you should instead use a method of EditorPlugin to get an EditorInterface singleton. It doesn't imply or directly tell that there is supposed to be an EditorPlugin singleton. EditorPlugin, in fact, cannot be a singleton. (Though we could make the getter for EditorInterface static). |
It literally says there is a singleton and how to access it. "Instead, access the singleton using EditorPlugin.get_editor_interface." If there isn't going to be a singleton, the docs need to change. A static getter would be great. I don't care about the singleton, I just want the editor camera. Instancing a class to get it is unnecessary. |
Yes, it literally says how to get an EditorInterface singleton, not an EditorPlugin singleton. It refers to a method of the EditorPlugin class to get the EditorInterface singleton. The EditorInterface has only one instance in the entire runtime, and is internally accessed using a singleton pattern. It is not exposed to the userland API as a named singleton, but it is still one. You just need to get a reference to it using a method of EditorPlugin. The form |
Ah, I understand. You are right. It is confusing because it looks like it is giving a code example of accessing the EP singleton as is done on other classes like the servers. |
I see in the code, EditorInterface has a singleton available. I attempted to retreive it from the engine I see Why not just expose the EditorInterface singleton directly rather than have two other classes hand it out? I attempted to make the function in EditorPlugin static, but the engine wouldn't build, giving me problems with class_db.h. Is this an easy fix?
|
Honestly, not sure why it wasn't exposed like that. I can guess that being an editor-only class having it as a global, named singleton may lead to problems with exported projects that rely on it. But can also be just how it was implemented many years ago for no particular reason. We also don't really support interacting with the editor UI from tool scripts. It just works because the editor is just a set of controls and other nodes, and GDScript can run in editor. But the way I see the current system is designed, there was never an intention for you to do what you attempt to do without creating an editor plugin and putting your world building tools in there.
The method needs to be bound to the API as static as well. You need to use |
|
Ok thank you, the |
Yes, that sample is incorrect. |
It's over a year ago and the "incorrect" example is still there and confuses people like me who are looking to find a way to access the editor settings :( |
@Owlmate-Julius The example works as of 4.2 where |
Godot version
Godot 4 Beta 4
System information
Windows 11/64, RTX 3070, Vulkan
Issue description
The
EditorPlugin
singleton doesn't work. Or the documentation needs to be updated.The docs say this:
Note: This class shouldn't be instantiated directly. Instead, access the singleton using EditorPlugin.get_editor_interface.
However if I write:
The editor reports this:
SCRIPT ERROR: Parse Error: Cannot call non-static function "get_editor_interface()" on the class "EditorPlugin" directly. Make an instance instead. at: GDScript::reload (res://node_3d.gd:35)
So I either have to make a class derived from EditorPlugin, which I don't wish to as I just want the editor camera position. Or I have to do what the docs say to not do:
For my terrain system I want it updating based on camera position in the editor. I'm not writing an editor plugin. I just want the position. I wrote this code segment to get the editor cameras outside of an EP:
godotengine/godot-proposals#1302 (comment)
Steps to reproduce
n/a
Minimal reproduction project
No response
The text was updated successfully, but these errors were encountered: