Class reference

ResourceSaver

Inherits Object

A singleton for saving Resources to the filesystem.

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

PackedStringArray get_recognized_extensions(Resource type)

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

int get_resource_id_for_path(String path, bool generate = false)

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.

int save(Resource resource, String path = "", int flags = 0)

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.

int set_uid(String resource, int uid)

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.

Constants

FLAG_NONE = 0

Enum: SaverFlags

No resource saving option.

FLAG_RELATIVE_PATHS = 1

Enum: SaverFlags

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

FLAG_BUNDLE_RESOURCES = 2

Enum: SaverFlags

Bundles external resources.

FLAG_CHANGE_PATH = 4

Enum: SaverFlags

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

FLAG_OMIT_EDITOR_PROPERTIES = 8

Enum: SaverFlags

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

FLAG_COMPRESS = 32

Enum: SaverFlags

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

FLAG_REPLACE_SUBRESOURCE_PATHS = 64

Enum: SaverFlags

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

Source revision 4f5b14abade2
Connection interrupted. Reload×

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.