class_resourcesaver.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/ResourceSaver.xml.
  6. .. _class_ResourceSaver:
  7. ResourceSaver
  8. =============
  9. **Inherits:** :ref:`Object<class_Object>`
  10. A singleton for saving :ref:`Resource<class_Resource>`\ s to the filesystem.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. A singleton for saving resource types to the filesystem.
  15. 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``).
  16. .. rst-class:: classref-reftable-group
  17. Methods
  18. -------
  19. .. table::
  20. :widths: auto
  21. +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | |void| | :ref:`add_resource_format_saver<class_ResourceSaver_method_add_resource_format_saver>`\ (\ format_saver\: :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`, at_front\: :ref:`bool<class_bool>` = false\ ) |
  23. +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_recognized_extensions<class_ResourceSaver_method_get_recognized_extensions>`\ (\ type\: :ref:`Resource<class_Resource>`\ ) |
  25. +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`int<class_int>` | :ref:`get_resource_id_for_path<class_ResourceSaver_method_get_resource_id_for_path>`\ (\ path\: :ref:`String<class_String>`, generate\: :ref:`bool<class_bool>` = false\ ) |
  27. +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | |void| | :ref:`remove_resource_format_saver<class_ResourceSaver_method_remove_resource_format_saver>`\ (\ format_saver\: :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`\ ) |
  29. +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save<class_ResourceSaver_method_save>`\ (\ resource\: :ref:`Resource<class_Resource>`, path\: :ref:`String<class_String>` = "", flags\: |bitfield|\[:ref:`SaverFlags<enum_ResourceSaver_SaverFlags>`\] = 0\ ) |
  31. +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`set_uid<class_ResourceSaver_method_set_uid>`\ (\ resource\: :ref:`String<class_String>`, uid\: :ref:`int<class_int>`\ ) |
  33. +---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. .. rst-class:: classref-section-separator
  35. ----
  36. .. rst-class:: classref-descriptions-group
  37. Enumerations
  38. ------------
  39. .. _enum_ResourceSaver_SaverFlags:
  40. .. rst-class:: classref-enumeration
  41. flags **SaverFlags**: :ref:`🔗<enum_ResourceSaver_SaverFlags>`
  42. .. _class_ResourceSaver_constant_FLAG_NONE:
  43. .. rst-class:: classref-enumeration-constant
  44. :ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` **FLAG_NONE** = ``0``
  45. No resource saving option.
  46. .. _class_ResourceSaver_constant_FLAG_RELATIVE_PATHS:
  47. .. rst-class:: classref-enumeration-constant
  48. :ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` **FLAG_RELATIVE_PATHS** = ``1``
  49. Save the resource with a path relative to the scene which uses it.
  50. .. _class_ResourceSaver_constant_FLAG_BUNDLE_RESOURCES:
  51. .. rst-class:: classref-enumeration-constant
  52. :ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` **FLAG_BUNDLE_RESOURCES** = ``2``
  53. Bundles external resources.
  54. .. _class_ResourceSaver_constant_FLAG_CHANGE_PATH:
  55. .. rst-class:: classref-enumeration-constant
  56. :ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` **FLAG_CHANGE_PATH** = ``4``
  57. Changes the :ref:`Resource.resource_path<class_Resource_property_resource_path>` of the saved resource to match its new location.
  58. .. _class_ResourceSaver_constant_FLAG_OMIT_EDITOR_PROPERTIES:
  59. .. rst-class:: classref-enumeration-constant
  60. :ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` **FLAG_OMIT_EDITOR_PROPERTIES** = ``8``
  61. Do not save editor-specific metadata (identified by their ``__editor`` prefix).
  62. .. _class_ResourceSaver_constant_FLAG_SAVE_BIG_ENDIAN:
  63. .. rst-class:: classref-enumeration-constant
  64. :ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` **FLAG_SAVE_BIG_ENDIAN** = ``16``
  65. Save as big endian (see :ref:`FileAccess.big_endian<class_FileAccess_property_big_endian>`).
  66. .. _class_ResourceSaver_constant_FLAG_COMPRESS:
  67. .. rst-class:: classref-enumeration-constant
  68. :ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` **FLAG_COMPRESS** = ``32``
  69. Compress the resource on save using :ref:`FileAccess.COMPRESSION_ZSTD<class_FileAccess_constant_COMPRESSION_ZSTD>`. Only available for binary resource types.
  70. .. _class_ResourceSaver_constant_FLAG_REPLACE_SUBRESOURCE_PATHS:
  71. .. rst-class:: classref-enumeration-constant
  72. :ref:`SaverFlags<enum_ResourceSaver_SaverFlags>` **FLAG_REPLACE_SUBRESOURCE_PATHS** = ``64``
  73. Take over the paths of the saved subresources (see :ref:`Resource.take_over_path()<class_Resource_method_take_over_path>`).
  74. .. rst-class:: classref-section-separator
  75. ----
  76. .. rst-class:: classref-descriptions-group
  77. Method Descriptions
  78. -------------------
  79. .. _class_ResourceSaver_method_add_resource_format_saver:
  80. .. rst-class:: classref-method
  81. |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>`
  82. Registers a new :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`. The ResourceSaver will use the ResourceFormatSaver as described in :ref:`save()<class_ResourceSaver_method_save>`.
  83. This method is performed implicitly for ResourceFormatSavers written in GDScript (see :ref:`ResourceFormatSaver<class_ResourceFormatSaver>` for more information).
  84. .. rst-class:: classref-item-separator
  85. ----
  86. .. _class_ResourceSaver_method_get_recognized_extensions:
  87. .. rst-class:: classref-method
  88. :ref:`PackedStringArray<class_PackedStringArray>` **get_recognized_extensions**\ (\ type\: :ref:`Resource<class_Resource>`\ ) :ref:`🔗<class_ResourceSaver_method_get_recognized_extensions>`
  89. Returns the list of extensions available for saving a resource of a given type.
  90. .. rst-class:: classref-item-separator
  91. ----
  92. .. _class_ResourceSaver_method_get_resource_id_for_path:
  93. .. rst-class:: classref-method
  94. :ref:`int<class_int>` **get_resource_id_for_path**\ (\ path\: :ref:`String<class_String>`, generate\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_ResourceSaver_method_get_resource_id_for_path>`
  95. 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<class_ResourceUID_constant_INVALID_ID>` is returned.
  96. .. rst-class:: classref-item-separator
  97. ----
  98. .. _class_ResourceSaver_method_remove_resource_format_saver:
  99. .. rst-class:: classref-method
  100. |void| **remove_resource_format_saver**\ (\ format_saver\: :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`\ ) :ref:`🔗<class_ResourceSaver_method_remove_resource_format_saver>`
  101. Unregisters the given :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`.
  102. .. rst-class:: classref-item-separator
  103. ----
  104. .. _class_ResourceSaver_method_save:
  105. .. rst-class:: classref-method
  106. :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>`
  107. 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>`.
  108. The ``flags`` bitmask can be specified to customize the save behavior.
  109. Returns :ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success.
  110. \ **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.
  111. .. rst-class:: classref-item-separator
  112. ----
  113. .. _class_ResourceSaver_method_set_uid:
  114. .. rst-class:: classref-method
  115. :ref:`Error<enum_@GlobalScope_Error>` **set_uid**\ (\ resource\: :ref:`String<class_String>`, uid\: :ref:`int<class_int>`\ ) :ref:`🔗<class_ResourceSaver_method_set_uid>`
  116. Sets the UID of the given ``resource`` path to ``uid``. You can generate a new UID using :ref:`ResourceUID.create_id()<class_ResourceUID_method_create_id>`.
  117. Since resources will normally get a UID automatically, this method is only useful in very specific cases.
  118. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  119. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  120. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  121. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  122. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  123. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  124. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  125. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  126. .. |void| replace:: :abbr:`void (No return value.)`