Saving data for editor plugins

Godot Version



when I change variables in the inspector, edit nodes in the scene or change anything in the editor, the variables are saved.
What I want is the same thing for my Editor pugin.
Is there a way to save these changes? I mean, under _enter_tree, I could load data from a save file, when the plugin starts up…
but instead of this, Id prefer not to have to create a new file in my resources for this…

could I save a string or int somewhere in the scene? Or into the editor somewhere? it’s really not much data, just to remember a few settings of my Editor plugin when the editor starts up…
any suggestions?

1 Like

Whatever you want saved should be an @export var foo:type in your custom node. You can also make custom Resources (they also use @export) and they will also save their data.

its not working… I just want it to load as null, then push button it is 5, then reload plugin and get 5.

extends EditorPlugin

 @export var foo:int

func _enter_tree():
        print( foo );
	add_custom_type("MyButton", "Button", preload(""), preload("icon.png"))

func my_button_pressed():
	foo = 5;

func _exit_tree():

You should probably use _get_state and _set_state

1 Like

It depends on what you want to save and when do you want to save it.

You can save the plugin/editor status so is restored when the editor is reloaded. You can save arbitrary Data on specific moments, there are many cases for when and what data is going to be saved so we need to know that to provide a better answer

I want to save a string that will be the path to a resource file (an image).
the user will load the editor and when they select the button next to the resource they can change the image. When reloading the editor, the previously selected image will show up.

so in the top example, @export var foo:int
would be @export var foo:string

and I would put a panel or rectangle with showing the image selected.
then add the button:
add_custom_type(“MyButton”, “Load Image”, preload(“”), preload(“icon.png”))
that when pressed bring the dialog to open a new image.

all this I already have in my code and its pretty standard. just a button and dialog to open file. What I want is to save that for future reloads so I dont need to always re-open that file at startup!

1 Like

Yeah, pretty awkward…
The vars dont get saved, when the scene is run… Its the same thing has changing the X and Y on a Node then run the scene and the values get reseted to zero…

And Looking by the answers on this post, makes me laugh… Another NEEDLE IN THE HAYSTACK, that we are left out to search for… not knowing if its possible or if it exists or not ?

This post is the only thing that shows on a google seach “How to save plugIn vars”

this worked for me: although… ( Canvas tex Dictionary size 0 ) its always at zero in the editor, its dificult understand…

extends Node2D

@export var canvasTex = {}; 

var drawText;

func _draw():
	for i in canvasTex: 
		draw_texture( canvasTex[i], i );

even if you reload the scene?

even if you reload the scene?

Ive just tested it and it worked… good eye :+1: It updates in the editor, when clicking on another scene on the top menu then return back to the scene were @tool is.

but, i couldnt get the funcs working ( _get_state and _set_state )… it seems they only work on " extends EditorPlugin "