github_url: | hide |
---|
Inherits: :ref:`Object<class_Object>`
A singleton for saving :ref:`Resource<class_Resource>`s to the filesystem.
.. rst-class:: classref-introduction-group
A singleton for saving resource types to the filesystem.
It uses the many :ref:`ResourceFormatSaver<class_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
).
.. rst-class:: classref-reftable-group
.. rst-class:: classref-section-separator
.. rst-class:: classref-descriptions-group
.. rst-class:: classref-enumeration
flags SaverFlags: :ref:`🔗<enum_ResourceSaver_SaverFlags>`
.. rst-class:: classref-enumeration-constant
:ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` FLAG_NONE = 0
No resource saving option.
.. rst-class:: classref-enumeration-constant
:ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` FLAG_RELATIVE_PATHS = 1
Save the resource with a path relative to the scene which uses it.
.. rst-class:: classref-enumeration-constant
:ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` FLAG_BUNDLE_RESOURCES = 2
Bundles external resources.
.. rst-class:: classref-enumeration-constant
:ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` FLAG_CHANGE_PATH = 4
Changes the :ref:`Resource.resource_path<class_Resource_property_resource_path>` of the saved resource to match its new location.
.. rst-class:: classref-enumeration-constant
:ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` FLAG_OMIT_EDITOR_PROPERTIES = 8
Do not save editor-specific metadata (identified by their __editor
prefix).
.. rst-class:: classref-enumeration-constant
:ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` FLAG_SAVE_BIG_ENDIAN = 16
Save as big endian (see :ref:`FileAccess.big_endian<class_FileAccess_property_big_endian>`).
.. rst-class:: classref-enumeration-constant
:ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` FLAG_COMPRESS = 32
Compress the resource on save using :ref:`FileAccess.COMPRESSION_ZSTD<class_FileAccess_constant_COMPRESSION_ZSTD>`. Only available for binary resource types.
.. rst-class:: classref-enumeration-constant
:ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` FLAG_REPLACE_SUBRESOURCE_PATHS = 64
Take over the paths of the saved subresources (see :ref:`Resource.take_over_path<class_Resource_method_take_over_path>`).
.. rst-class:: classref-section-separator
.. rst-class:: classref-descriptions-group
.. rst-class:: classref-method
|void| add_resource_format_saver(format_saver: :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`, at_front: :ref:`bool<class_bool>` = false) :ref:`🔗<class_ResourceSaver_method_add_resource_format_saver>`
Registers a new :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`. The ResourceSaver will use the ResourceFormatSaver as described in :ref:`save<class_ResourceSaver_method_save>`.
This method is performed implicitly for ResourceFormatSavers written in GDScript (see :ref:`ResourceFormatSaver<class_ResourceFormatSaver>` for more information).
.. rst-class:: classref-item-separator
.. rst-class:: classref-method
:ref:`PackedStringArray<class_PackedStringArray>` get_recognized_extensions(type: :ref:`Resource<class_Resource>`) :ref:`🔗<class_ResourceSaver_method_get_recognized_extensions>`
Returns the list of extensions available for saving a resource of a given type.
.. rst-class:: classref-item-separator
.. rst-class:: classref-method
|void| remove_resource_format_saver(format_saver: :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`) :ref:`🔗<class_ResourceSaver_method_remove_resource_format_saver>`
Unregisters the given :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`.
.. rst-class:: classref-item-separator
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` save(resource: :ref:`Resource<class_Resource>`, path: :ref:`String<class_String>` = "", flags: |bitfield|[:ref:`SaverFlags<enum_ResourceSaver_SaverFlags>`] = 0) :ref:`🔗<class_ResourceSaver_method_save>`
Saves a resource to disk to the given path, using a :ref:`ResourceFormatSaver<class_ResourceFormatSaver>` that recognizes the resource object. If path
is empty, ResourceSaver will try to use :ref:`Resource.resource_path<class_Resource_property_resource_path>`.
The flags
bitmask can be specified to customize the save behavior using :ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` flags.
Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_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.