Why does EditorSettings.some_method() not work?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gswashburn

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 which context are you using EditorSettings? These are editor-only, it’s normal they don’t work ingame.

Zylann | 2018-03-19 18:33

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

gswashburn | 2018-03-19 21:52

:bust_in_silhouette: Reply From: Footurist

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. :stuck_out_tongue:

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. ‘property_list()’ works, has_method(‘method name’) works etc.

gswashburn | 2018-03-20 14:43

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.

Footurist | 2018-03-20 21:54

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

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.plugin_path = 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/plugin_path but that’s for another post.

Thanks for the help, Gerry

gswashburn | 2018-03-21 21:22