0 votes

Why does this not work?

    var fldr = EditorSettings.get_setting("filesystem/directories/default_project_path")
print(fldr) 

I can get this to work

    var fldr = ProjectSettings.get_setting("logging/file_logging/log_path")
    print(fldr) 
in Engine by (204 points)

In which context are you using EditorSettings? These are editor-only, it's normal they don't work ingame.

I am using them in an editor plugin I am developing.

1 Answer

0 votes
Best answer

This works:

var settings = EditorSettings.new()
print(settings.get_setting("filesystem/directories/default_project_path"))

For some reason idk right now, you have to create an object for EditorSettings, but not for ProjectSettings. Maybe some other user can enlighten us, I am as confused as you are.

EDIT:
If you look at the docs, you will see that ProjectSettings is in global scope as a singleton, EditorSettings not. That's why you do not have to create the object for ProjectSettings. :P

by (840 points)
selected by

I tried that before and it didn't work.

func _ready():
    var settings = EditorSettings.new()
    print(settings.get_setting("filesystem/directories/default_project_path"))

I got this error:
Nonexistent function 'get_setting' in base 'NIL'

I also tried it this way

tool
extends Control

var settings = EditorSettings.new()

func _ready():
    print(settings.get_setting("filesystem/directories/default_project_path"))

I got this error:
Nonexistent function 'get_setting' in base 'NIL'

I also tried it this way

tool
extends Control

var settings = EditorSettings    
func _ready():
    print(settings.get_setting("filesystem/directories/default_project_path"))

I got this error:
Nonexistent function 'get_setting' in base 'GDscriptNativeClass'

So I am still not sure how to use it. All the methods and settings were there, but only some work. 'propertylist()' works, hasmethod('method name') works etc.

You're trying to do what Zylann already told you is not possible: Using EditorSettings at runtime. Because this is essentially where _ready() will be called in your tool!
I've tested the code in my answer and it'll work like this:

tool
extends Node2D

func _enter_tree():
    var settings = EditorSettings.new()
    print(settings.get_setting("filesystem/directories/default_project_path"))

Hope, this helps.

So in order to get the current values in the Editor Settings I had to do it differently by using geteditorinterface().geteditorsettings()

tool
extends EditorPlugin

var ed = get_editor_interface().get_editor_settings()

func _enter_tree(): 
 dock = preload("res://addons/plugin/plugin_dock.tscn").instance()
 add_control_to_dock( EditorPlugin.DOCK_SLOT_LEFT_BR, dock)
 var results = ed.get_setting("filesystem/directories/default_project_path")
 dock.plugin_path = results
 print(results)        

I then pushed the value into my Editor Plugin GUI using the preload instance and variable name dock.pluginpath = results. This allowed me to get the current path on my system versus the initial default values. I then took it another step further and stored the value in Editor Settings under filesystem/directories/pluginpath but that's for another post.

Thanks for the help, Gerry

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.