Skip to content
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

Make EditorSettings accessible as a singleton, to be able to access outside EditorPlugin #3511

Closed
Tracked by #7
ghsoares opened this issue Nov 6, 2021 · 3 comments
Closed
Tracked by #7

Comments

@ghsoares
Copy link

ghsoares commented Nov 6, 2021

Describe the project you are working on

ReactGD, right now developing a gdnative plugin

Describe the problem or limitation you are having in your project

I wanted to get a editor setting for my plugin, more specifically network/language_server/remote_port to get the gdscript LSP and connect to it from my gdnative plugin. The problem is that EditorSettings is not a singleton like ProjectSettings, so to access it, you need to get it from EditorInterface which is only available for EditorPlugin.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The feature is to turn EditorSettings an editor-only singleton, that means that it would only be accessed if inside editor, not being able to access it in builds. The user must ensure that it is only referencing it inside editor-only code blocks, if Engine.editor_hint for gdscript or #if TOOLS_ENABLED for gdnative (I don't remember if gdnative have this define).

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

For gdnative, it would have a static function EditorSettings *get_singleton() which would return the singleton instance of the editor settings. For GDScript, it would be as simple as referencing EditorSettings in any place of the code.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, there's no other way to access EditorSettings outside EditorPlugin.

Is there a reason why this should be core and not an add-on in the asset library?

Same as above.

@Xrayez
Copy link
Contributor

Xrayez commented Nov 19, 2021

I've tried to expose the singleton in Goost (via module), but fail to do so. It's possible to add a singleton, but the returned EditorSettings instance turns out to be null. I think this something has to do with order of initialization in main() (register_module_types() may be called too early).

@KoBeWi
Copy link
Member

KoBeWi commented Jul 12, 2022

I think it would be better to to add get_editor_interface() to SceneTree, so it can be accessed in any tool script. The method would return null when not inside editor.

@aaronfranke
Copy link
Member

aaronfranke commented Apr 21, 2024

This is now implemented as of godotengine/godot#75694 which is merged into Godot 4.2 and later.

You can access EditorSettings using var editor_settings = EditorInterface.get_editor_settings()

@aaronfranke aaronfranke added this to the 4.2 milestone Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants