How to call the save button in the inspector from a script

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

I’ve defined an array of custom resources with setget that limits the type.

However, after changing the value of a resource, I noticed that the value is not reflected until I press the save button on the inspector.

extends Resource
export(Array,Resource) var resource_array setget _set_array

func _set_array(new_value : Array):
    	var helper =
    	resource_array =helper.CreateArray(new_value,audiostream)

func CreateArray(new_value,from_resource) -> Array:
	var result = []
	for element in new_value:
		var elem = element 
		if elem == null:
			elem =
			elem.m_resource = from_resource.duplicate()
	return result

When I refer to the resource in the tool script, the changed data is reflected, but the
When I run the game, the values are not reflected; when I open the tres file, the changed values are not written.

I am afraid of forgetting to save and losing data, so I want to execute the inspector’s save button from a script or with a shortcut key.

I tried property_list_changed_notify() but it did not work.

:bust_in_silhouette: Reply From: CodeEnder

Have the button call a function that does the saving. You can then call that same function by script, no need to try and press the button by script or whatever.

Thanks for the answer! didn’t seem to work if I passed the path to the resource generated by setget (the path that is automatically generated when put into the array). I solved the problem by specifying the path of the resource first and saving it.

heart_valve | 2022-11-20 01:52