Index · Object → ResourceSaver

ResourceSaver

A singleton for saving Resources to the filesystem.

Class Description

A singleton for saving resource types to the filesystem.

It uses the many ResourceFormatSaver classes registered in the engine (either built-in or from a plugin) to save resource data to text-based (e.g. .tres or .tscn) or binary files (e.g. .res or .scn).

Methods

func add_resource_format_saver(format_saver: ResourceFormatSaver, at_front: bool = false) -> void

Registers a new ResourceFormatSaver. The ResourceSaver will use the ResourceFormatSaver as described in save().

This method is performed implicitly for ResourceFormatSavers written in GDScript (see ResourceFormatSaver for more information).

func get_recognized_extensions(type: Resource) -> PackedStringArray

Returns the list of extensions available for saving a resource of a given type.

func get_resource_id_for_path(path: String, generate: bool = false) -> int

Returns the resource ID for the given path. If generate is true, a new resource ID will be generated if one for the path is not found. If generate is false and the path is not found, ResourceUID.INVALID_ID is returned.

func remove_resource_format_saver(format_saver: ResourceFormatSaver) -> void

Unregisters the given ResourceFormatSaver.

func save(resource: Resource, path: String = "", flags: ResourceSaver.SaverFlags = 0) -> Error

Saves a resource to disk to the given path, using a ResourceFormatSaver that recognizes the resource object. If path is empty, ResourceSaver will try to use Resource.resource_path.

The flags bitmask can be specified to customize the save behavior.

Returns OK on success.

Note: When the project is running, any generated UID associated with the resource will not be saved as the required code is only executed in editor mode.

func set_uid(resource: String, uid: int) -> Error

Sets the UID of the given resource path to uid. You can generate a new UID using ResourceUID.create_id().

Since resources will normally get a UID automatically, this method is only useful in very specific cases.

Inherited from Object (62)
func _get(property: StringName) -> Variant
func _get_property_list() -> Dictionary[]
func _init() -> void
func _iter_get(iter: Variant) -> Variant
func _iter_init(iter: Array) -> bool
func _iter_next(iter: Array) -> bool
func _notification(what: int) -> void
func _set(property: StringName, value: Variant) -> bool
func _to_string() -> String
func _validate_property(property: Dictionary) -> void
func add_user_signal(signal: String, arguments: Array = []) -> void
func call(method: StringName) -> Variant
func callv(method: StringName, arg_array: Array) -> Variant
func cancel_free() -> void
func connect(signal: StringName, callable: Callable, flags: int = 0) -> Error
func disconnect(signal: StringName, callable: Callable) -> void
func emit_signal(signal: StringName) -> Error
func free() -> void
func get(property: StringName) -> Variant
func get_class() -> String
func get_incoming_connections() -> Dictionary[]
func get_indexed(property_path: NodePath) -> Variant
func get_meta(name: StringName, default: Variant = null) -> Variant
func get_meta_list() -> StringName[]
func get_method_list() -> Dictionary[]
func get_property_list() -> Dictionary[]
func get_signal_connection_list(signal: StringName) -> Dictionary[]
func get_signal_list() -> Dictionary[]
func has_meta(name: StringName) -> bool
func has_method(method: StringName) -> bool
func has_signal(signal: StringName) -> bool
func is_class(class: StringName) -> bool
func is_connected(signal: StringName, callable: Callable) -> bool
func notification(what: int, reversed: bool = false) -> void
func remove_meta(name: StringName) -> void
func remove_user_signal(signal: StringName) -> void
func set(property: StringName, value: Variant) -> void
func set_block_signals(enable: bool) -> void
func set_deferred(property: StringName, value: Variant) -> void
func set_indexed(property_path: NodePath, value: Variant) -> void
func set_message_translation(enable: bool) -> void
func set_meta(name: StringName, value: Variant) -> void
func set_script(script: Variant) -> void
func set_translation_domain(domain: StringName) -> void
func to_string() -> String
func tr(message: StringName, context: StringName = &"") -> String
func tr_n(message: StringName, plural_message: StringName, n: int, context: StringName = &"") -> String

Signals

Inherited from Object (2)

Enums & Constants

enum SaverFlags
FLAG_NONE = 0

No resource saving option.

FLAG_RELATIVE_PATHS = 1

Save the resource with a path relative to the scene which uses it.

FLAG_BUNDLE_RESOURCES = 2

Bundles external resources.

FLAG_CHANGE_PATH = 4

Changes the Resource.resource_path of the saved resource to match its new location.

FLAG_OMIT_EDITOR_PROPERTIES = 8

Do not save editor-specific metadata (identified by their __editor prefix).

FLAG_SAVE_BIG_ENDIAN = 16

Save as big endian (see FileAccess.big_endian).

FLAG_COMPRESS = 32

Compress the resource on save using FileAccess.COMPRESSION_ZSTD. Only available for binary resource types.

FLAG_REPLACE_SUBRESOURCE_PATHS = 64

Take over the paths of the saved subresources (see Resource.take_over_path()).