:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/ResourceSaver.xml. .. _class_ResourceSaver: ResourceSaver ============= **Inherits:** :ref:`Object` A singleton for saving :ref:`Resource`\ s to the filesystem. .. rst-class:: classref-introduction-group Description ----------- A singleton for saving resource types to the filesystem. It uses the many :ref:`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 Methods ------- .. table:: :widths: auto +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_resource_format_saver`\ (\ format_saver\: :ref:`ResourceFormatSaver`, at_front\: :ref:`bool` = false\ ) | +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedStringArray` | :ref:`get_recognized_extensions`\ (\ type\: :ref:`Resource`\ ) | +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_resource_id_for_path`\ (\ path\: :ref:`String`, generate\: :ref:`bool` = false\ ) | +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`remove_resource_format_saver`\ (\ format_saver\: :ref:`ResourceFormatSaver`\ ) | +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`save`\ (\ resource\: :ref:`Resource`, path\: :ref:`String` = "", flags\: |bitfield|\[:ref:`SaverFlags`\] = 0\ ) | +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`set_uid`\ (\ resource\: :ref:`String`, uid\: :ref:`int`\ ) | +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Enumerations ------------ .. _enum_ResourceSaver_SaverFlags: .. rst-class:: classref-enumeration flags **SaverFlags**: :ref:`🔗` .. _class_ResourceSaver_constant_FLAG_NONE: .. rst-class:: classref-enumeration-constant :ref:`SaverFlags` **FLAG_NONE** = ``0`` No resource saving option. .. _class_ResourceSaver_constant_FLAG_RELATIVE_PATHS: .. rst-class:: classref-enumeration-constant :ref:`SaverFlags` **FLAG_RELATIVE_PATHS** = ``1`` Save the resource with a path relative to the scene which uses it. .. _class_ResourceSaver_constant_FLAG_BUNDLE_RESOURCES: .. rst-class:: classref-enumeration-constant :ref:`SaverFlags` **FLAG_BUNDLE_RESOURCES** = ``2`` Bundles external resources. .. _class_ResourceSaver_constant_FLAG_CHANGE_PATH: .. rst-class:: classref-enumeration-constant :ref:`SaverFlags` **FLAG_CHANGE_PATH** = ``4`` Changes the :ref:`Resource.resource_path` of the saved resource to match its new location. .. _class_ResourceSaver_constant_FLAG_OMIT_EDITOR_PROPERTIES: .. rst-class:: classref-enumeration-constant :ref:`SaverFlags` **FLAG_OMIT_EDITOR_PROPERTIES** = ``8`` Do not save editor-specific metadata (identified by their ``__editor`` prefix). .. _class_ResourceSaver_constant_FLAG_SAVE_BIG_ENDIAN: .. rst-class:: classref-enumeration-constant :ref:`SaverFlags` **FLAG_SAVE_BIG_ENDIAN** = ``16`` Save as big endian (see :ref:`FileAccess.big_endian`). .. _class_ResourceSaver_constant_FLAG_COMPRESS: .. rst-class:: classref-enumeration-constant :ref:`SaverFlags` **FLAG_COMPRESS** = ``32`` Compress the resource on save using :ref:`FileAccess.COMPRESSION_ZSTD`. Only available for binary resource types. .. _class_ResourceSaver_constant_FLAG_REPLACE_SUBRESOURCE_PATHS: .. rst-class:: classref-enumeration-constant :ref:`SaverFlags` **FLAG_REPLACE_SUBRESOURCE_PATHS** = ``64`` Take over the paths of the saved subresources (see :ref:`Resource.take_over_path()`). .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_ResourceSaver_method_add_resource_format_saver: .. rst-class:: classref-method |void| **add_resource_format_saver**\ (\ format_saver\: :ref:`ResourceFormatSaver`, at_front\: :ref:`bool` = false\ ) :ref:`🔗` Registers a new :ref:`ResourceFormatSaver`. The ResourceSaver will use the ResourceFormatSaver as described in :ref:`save()`. This method is performed implicitly for ResourceFormatSavers written in GDScript (see :ref:`ResourceFormatSaver` for more information). .. rst-class:: classref-item-separator ---- .. _class_ResourceSaver_method_get_recognized_extensions: .. rst-class:: classref-method :ref:`PackedStringArray` **get_recognized_extensions**\ (\ type\: :ref:`Resource`\ ) :ref:`🔗` Returns the list of extensions available for saving a resource of a given type. .. rst-class:: classref-item-separator ---- .. _class_ResourceSaver_method_get_resource_id_for_path: .. rst-class:: classref-method :ref:`int` **get_resource_id_for_path**\ (\ path\: :ref:`String`, generate\: :ref:`bool` = false\ ) :ref:`🔗` 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, :ref:`ResourceUID.INVALID_ID` is returned. .. rst-class:: classref-item-separator ---- .. _class_ResourceSaver_method_remove_resource_format_saver: .. rst-class:: classref-method |void| **remove_resource_format_saver**\ (\ format_saver\: :ref:`ResourceFormatSaver`\ ) :ref:`🔗` Unregisters the given :ref:`ResourceFormatSaver`. .. rst-class:: classref-item-separator ---- .. _class_ResourceSaver_method_save: .. rst-class:: classref-method :ref:`Error` **save**\ (\ resource\: :ref:`Resource`, path\: :ref:`String` = "", flags\: |bitfield|\[:ref:`SaverFlags`\] = 0\ ) :ref:`🔗` Saves a resource to disk to the given path, using a :ref:`ResourceFormatSaver` that recognizes the resource object. If ``path`` is empty, **ResourceSaver** will try to use :ref:`Resource.resource_path`. The ``flags`` bitmask can be specified to customize the save behavior. Returns :ref:`@GlobalScope.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. .. rst-class:: classref-item-separator ---- .. _class_ResourceSaver_method_set_uid: .. rst-class:: classref-method :ref:`Error` **set_uid**\ (\ resource\: :ref:`String`, uid\: :ref:`int`\ ) :ref:`🔗` Sets the UID of the given ``resource`` path to ``uid``. You can generate a new UID using :ref:`ResourceUID.create_id()`. Since resources will normally get a UID automatically, this method is only useful in very specific cases. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)` .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)` .. |void| replace:: :abbr:`void (No return value.)`