class_resource.rst 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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/Resource.xml.
  6. .. _class_Resource:
  7. Resource
  8. ========
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`Animation<class_Animation>`, :ref:`AnimationLibrary<class_AnimationLibrary>`, :ref:`AnimationNode<class_AnimationNode>`, :ref:`AnimationNodeStateMachinePlayback<class_AnimationNodeStateMachinePlayback>`, :ref:`AnimationNodeStateMachineTransition<class_AnimationNodeStateMachineTransition>`, :ref:`AudioBusLayout<class_AudioBusLayout>`, :ref:`AudioEffect<class_AudioEffect>`, :ref:`AudioStream<class_AudioStream>`, :ref:`BitMap<class_BitMap>`, :ref:`BoneMap<class_BoneMap>`, :ref:`ButtonGroup<class_ButtonGroup>`, :ref:`CameraAttributes<class_CameraAttributes>`, :ref:`ColorPalette<class_ColorPalette>`, :ref:`Compositor<class_Compositor>`, :ref:`CompositorEffect<class_CompositorEffect>`, :ref:`CryptoKey<class_CryptoKey>`, :ref:`Curve<class_Curve>`, :ref:`Curve2D<class_Curve2D>`, :ref:`Curve3D<class_Curve3D>`, :ref:`EditorNode3DGizmoPlugin<class_EditorNode3DGizmoPlugin>`, :ref:`EditorSettings<class_EditorSettings>`, :ref:`Environment<class_Environment>`, :ref:`FoldableGroup<class_FoldableGroup>`, :ref:`Font<class_Font>`, :ref:`GDExtension<class_GDExtension>`, :ref:`GLTFAccessor<class_GLTFAccessor>`, :ref:`GLTFAnimation<class_GLTFAnimation>`, :ref:`GLTFBufferView<class_GLTFBufferView>`, :ref:`GLTFCamera<class_GLTFCamera>`, :ref:`GLTFDocument<class_GLTFDocument>`, :ref:`GLTFDocumentExtension<class_GLTFDocumentExtension>`, :ref:`GLTFLight<class_GLTFLight>`, :ref:`GLTFMesh<class_GLTFMesh>`, :ref:`GLTFNode<class_GLTFNode>`, :ref:`GLTFPhysicsBody<class_GLTFPhysicsBody>`, :ref:`GLTFPhysicsShape<class_GLTFPhysicsShape>`, :ref:`GLTFSkeleton<class_GLTFSkeleton>`, :ref:`GLTFSkin<class_GLTFSkin>`, :ref:`GLTFSpecGloss<class_GLTFSpecGloss>`, :ref:`GLTFState<class_GLTFState>`, :ref:`GLTFTexture<class_GLTFTexture>`, :ref:`GLTFTextureSampler<class_GLTFTextureSampler>`, :ref:`Gradient<class_Gradient>`, :ref:`Image<class_Image>`, :ref:`ImporterMesh<class_ImporterMesh>`, :ref:`InputEvent<class_InputEvent>`, :ref:`JSON<class_JSON>`, :ref:`LabelSettings<class_LabelSettings>`, :ref:`LightmapGIData<class_LightmapGIData>`, :ref:`Material<class_Material>`, :ref:`Mesh<class_Mesh>`, :ref:`MeshLibrary<class_MeshLibrary>`, :ref:`MissingResource<class_MissingResource>`, :ref:`MultiMesh<class_MultiMesh>`, :ref:`NavigationMesh<class_NavigationMesh>`, :ref:`NavigationMeshSourceGeometryData2D<class_NavigationMeshSourceGeometryData2D>`, :ref:`NavigationMeshSourceGeometryData3D<class_NavigationMeshSourceGeometryData3D>`, :ref:`NavigationPolygon<class_NavigationPolygon>`, :ref:`Noise<class_Noise>`, :ref:`Occluder3D<class_Occluder3D>`, :ref:`OccluderPolygon2D<class_OccluderPolygon2D>`, :ref:`OggPacketSequence<class_OggPacketSequence>`, :ref:`OpenXRAction<class_OpenXRAction>`, :ref:`OpenXRActionMap<class_OpenXRActionMap>`, :ref:`OpenXRActionSet<class_OpenXRActionSet>`, :ref:`OpenXRBindingModifier<class_OpenXRBindingModifier>`, :ref:`OpenXRHapticBase<class_OpenXRHapticBase>`, :ref:`OpenXRInteractionProfile<class_OpenXRInteractionProfile>`, :ref:`OpenXRIPBinding<class_OpenXRIPBinding>`, :ref:`PackedDataContainer<class_PackedDataContainer>`, :ref:`PackedScene<class_PackedScene>`, :ref:`PhysicsMaterial<class_PhysicsMaterial>`, :ref:`PolygonPathFinder<class_PolygonPathFinder>`, :ref:`RDShaderFile<class_RDShaderFile>`, :ref:`RDShaderSPIRV<class_RDShaderSPIRV>`, :ref:`RichTextEffect<class_RichTextEffect>`, :ref:`SceneReplicationConfig<class_SceneReplicationConfig>`, :ref:`Script<class_Script>`, :ref:`Shader<class_Shader>`, :ref:`ShaderInclude<class_ShaderInclude>`, :ref:`Shape2D<class_Shape2D>`, :ref:`Shape3D<class_Shape3D>`, :ref:`Shortcut<class_Shortcut>`, :ref:`SkeletonModification2D<class_SkeletonModification2D>`, :ref:`SkeletonModificationStack2D<class_SkeletonModificationStack2D>`, :ref:`SkeletonProfile<class_SkeletonProfile>`, :ref:`Skin<class_Skin>`, :ref:`Sky<class_Sky>`, :ref:`SpriteFrames<class_SpriteFrames>`, :ref:`StyleBox<class_StyleBox>`, :ref:`SyntaxHighlighter<class_SyntaxHighlighter>`, :ref:`Texture<class_Texture>`, :ref:`Theme<class_Theme>`, :ref:`TileMapPattern<class_TileMapPattern>`, :ref:`TileSet<class_TileSet>`, :ref:`TileSetSource<class_TileSetSource>`, :ref:`Translation<class_Translation>`, :ref:`VideoStream<class_VideoStream>`, :ref:`VideoStreamPlayback<class_VideoStreamPlayback>`, :ref:`VisualShaderNode<class_VisualShaderNode>`, :ref:`VoxelGIData<class_VoxelGIData>`, :ref:`World2D<class_World2D>`, :ref:`World3D<class_World3D>`, :ref:`X509Certificate<class_X509Certificate>`
  11. Base class for serializable objects.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. Resource is the base class for all Godot-specific resource types, serving primarily as data containers. Since they inherit from :ref:`RefCounted<class_RefCounted>`, resources are reference-counted and freed when no longer in use. They can also be nested within other resources, and saved on disk. :ref:`PackedScene<class_PackedScene>`, one of the most common :ref:`Object<class_Object>`\ s in a Godot project, is also a resource, uniquely capable of storing and instantiating the :ref:`Node<class_Node>`\ s it contains as many times as desired.
  16. In GDScript, resources can loaded from disk by their :ref:`resource_path<class_Resource_property_resource_path>` using :ref:`@GDScript.load()<class_@GDScript_method_load>` or :ref:`@GDScript.preload()<class_@GDScript_method_preload>`.
  17. The engine keeps a global cache of all loaded resources, referenced by paths (see :ref:`ResourceLoader.has_cached()<class_ResourceLoader_method_has_cached>`). A resource will be cached when loaded for the first time and removed from cache once all references are released. When a resource is cached, subsequent loads using its path will return the cached reference.
  18. \ **Note:** In C#, resources will not be freed instantly after they are no longer in use. Instead, garbage collection will run periodically and will free resources that are no longer in use. This means that unused resources will remain in memory for a while before being removed.
  19. .. rst-class:: classref-introduction-group
  20. Tutorials
  21. ---------
  22. - :doc:`Resources <../tutorials/scripting/resources>`
  23. - :doc:`When and how to avoid using nodes for everything <../tutorials/best_practices/node_alternatives>`
  24. .. rst-class:: classref-reftable-group
  25. Properties
  26. ----------
  27. .. table::
  28. :widths: auto
  29. +-----------------------------+-----------------------------------------------------------------------------------+-----------+
  30. | :ref:`bool<class_bool>` | :ref:`resource_local_to_scene<class_Resource_property_resource_local_to_scene>` | ``false`` |
  31. +-----------------------------+-----------------------------------------------------------------------------------+-----------+
  32. | :ref:`String<class_String>` | :ref:`resource_name<class_Resource_property_resource_name>` | ``""`` |
  33. +-----------------------------+-----------------------------------------------------------------------------------+-----------+
  34. | :ref:`String<class_String>` | :ref:`resource_path<class_Resource_property_resource_path>` | ``""`` |
  35. +-----------------------------+-----------------------------------------------------------------------------------+-----------+
  36. | :ref:`String<class_String>` | :ref:`resource_scene_unique_id<class_Resource_property_resource_scene_unique_id>` | |
  37. +-----------------------------+-----------------------------------------------------------------------------------+-----------+
  38. .. rst-class:: classref-reftable-group
  39. Methods
  40. -------
  41. .. table::
  42. :widths: auto
  43. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`RID<class_RID>` | :ref:`_get_rid<class_Resource_private_method__get_rid>`\ (\ ) |virtual| |const| |
  45. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | |void| | :ref:`_reset_state<class_Resource_private_method__reset_state>`\ (\ ) |virtual| |
  47. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | |void| | :ref:`_set_path_cache<class_Resource_private_method__set_path_cache>`\ (\ path\: :ref:`String<class_String>`\ ) |virtual| |const| |
  49. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | |void| | :ref:`_setup_local_to_scene<class_Resource_private_method__setup_local_to_scene>`\ (\ ) |virtual| |
  51. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Resource<class_Resource>` | :ref:`duplicate<class_Resource_method_duplicate>`\ (\ deep\: :ref:`bool<class_bool>` = false\ ) |const| |
  53. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Resource<class_Resource>` | :ref:`duplicate_deep<class_Resource_method_duplicate_deep>`\ (\ deep_subresources_mode\: :ref:`DeepDuplicateMode<enum_Resource_DeepDuplicateMode>` = 1\ ) |const| |
  55. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | |void| | :ref:`emit_changed<class_Resource_method_emit_changed>`\ (\ ) |
  57. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`String<class_String>` | :ref:`generate_scene_unique_id<class_Resource_method_generate_scene_unique_id>`\ (\ ) |static| |
  59. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`String<class_String>` | :ref:`get_id_for_path<class_Resource_method_get_id_for_path>`\ (\ path\: :ref:`String<class_String>`\ ) |const| |
  61. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`Node<class_Node>` | :ref:`get_local_scene<class_Resource_method_get_local_scene>`\ (\ ) |const| |
  63. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`RID<class_RID>` | :ref:`get_rid<class_Resource_method_get_rid>`\ (\ ) |const| |
  65. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`bool<class_bool>` | :ref:`is_built_in<class_Resource_method_is_built_in>`\ (\ ) |const| |
  67. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | |void| | :ref:`reset_state<class_Resource_method_reset_state>`\ (\ ) |
  69. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | |void| | :ref:`set_id_for_path<class_Resource_method_set_id_for_path>`\ (\ path\: :ref:`String<class_String>`, id\: :ref:`String<class_String>`\ ) |
  71. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | |void| | :ref:`set_path_cache<class_Resource_method_set_path_cache>`\ (\ path\: :ref:`String<class_String>`\ ) |
  73. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | |void| | :ref:`setup_local_to_scene<class_Resource_method_setup_local_to_scene>`\ (\ ) |
  75. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | |void| | :ref:`take_over_path<class_Resource_method_take_over_path>`\ (\ path\: :ref:`String<class_String>`\ ) |
  77. +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. .. rst-class:: classref-section-separator
  79. ----
  80. .. rst-class:: classref-descriptions-group
  81. Signals
  82. -------
  83. .. _class_Resource_signal_changed:
  84. .. rst-class:: classref-signal
  85. **changed**\ (\ ) :ref:`🔗<class_Resource_signal_changed>`
  86. Emitted when the resource changes, usually when one of its properties is modified. See also :ref:`emit_changed()<class_Resource_method_emit_changed>`.
  87. \ **Note:** This signal is not emitted automatically for properties of custom resources. If necessary, a setter needs to be created to emit the signal.
  88. .. rst-class:: classref-item-separator
  89. ----
  90. .. _class_Resource_signal_setup_local_to_scene_requested:
  91. .. rst-class:: classref-signal
  92. **setup_local_to_scene_requested**\ (\ ) :ref:`🔗<class_Resource_signal_setup_local_to_scene_requested>`
  93. **Deprecated:** This signal is only emitted when the resource is created. Override :ref:`_setup_local_to_scene()<class_Resource_private_method__setup_local_to_scene>` instead.
  94. Emitted by a newly duplicated resource with :ref:`resource_local_to_scene<class_Resource_property_resource_local_to_scene>` set to ``true``.
  95. .. rst-class:: classref-section-separator
  96. ----
  97. .. rst-class:: classref-descriptions-group
  98. Enumerations
  99. ------------
  100. .. _enum_Resource_DeepDuplicateMode:
  101. .. rst-class:: classref-enumeration
  102. enum **DeepDuplicateMode**: :ref:`🔗<enum_Resource_DeepDuplicateMode>`
  103. .. _class_Resource_constant_DEEP_DUPLICATE_NONE:
  104. .. rst-class:: classref-enumeration-constant
  105. :ref:`DeepDuplicateMode<enum_Resource_DeepDuplicateMode>` **DEEP_DUPLICATE_NONE** = ``0``
  106. No subresorces at all are duplicated. This is useful even in a deep duplication to have all the arrays and dictionaries duplicated but still pointing to the original resources.
  107. .. _class_Resource_constant_DEEP_DUPLICATE_INTERNAL:
  108. .. rst-class:: classref-enumeration-constant
  109. :ref:`DeepDuplicateMode<enum_Resource_DeepDuplicateMode>` **DEEP_DUPLICATE_INTERNAL** = ``1``
  110. Only subresources without a path or with a scene-local path will be duplicated.
  111. .. _class_Resource_constant_DEEP_DUPLICATE_ALL:
  112. .. rst-class:: classref-enumeration-constant
  113. :ref:`DeepDuplicateMode<enum_Resource_DeepDuplicateMode>` **DEEP_DUPLICATE_ALL** = ``2``
  114. Every subresource found will be duplicated, even if it has a non-local path. In other words, even potentially big resources stored separately will be duplicated.
  115. .. rst-class:: classref-section-separator
  116. ----
  117. .. rst-class:: classref-descriptions-group
  118. Property Descriptions
  119. ---------------------
  120. .. _class_Resource_property_resource_local_to_scene:
  121. .. rst-class:: classref-property
  122. :ref:`bool<class_bool>` **resource_local_to_scene** = ``false`` :ref:`🔗<class_Resource_property_resource_local_to_scene>`
  123. .. rst-class:: classref-property-setget
  124. - |void| **set_local_to_scene**\ (\ value\: :ref:`bool<class_bool>`\ )
  125. - :ref:`bool<class_bool>` **is_local_to_scene**\ (\ )
  126. If ``true``, the resource is duplicated for each instance of all scenes using it. At run-time, the resource can be modified in one scene without affecting other instances (see :ref:`PackedScene.instantiate()<class_PackedScene_method_instantiate>`).
  127. \ **Note:** Changing this property at run-time has no effect on already created duplicate resources.
  128. .. rst-class:: classref-item-separator
  129. ----
  130. .. _class_Resource_property_resource_name:
  131. .. rst-class:: classref-property
  132. :ref:`String<class_String>` **resource_name** = ``""`` :ref:`🔗<class_Resource_property_resource_name>`
  133. .. rst-class:: classref-property-setget
  134. - |void| **set_name**\ (\ value\: :ref:`String<class_String>`\ )
  135. - :ref:`String<class_String>` **get_name**\ (\ )
  136. An optional name for this resource. When defined, its value is displayed to represent the resource in the Inspector dock. For built-in scripts, the name is displayed as part of the tab name in the script editor.
  137. \ **Note:** Some resource formats do not support resource names. You can still set the name in the editor or via code, but it will be lost when the resource is reloaded. For example, only built-in scripts can have a resource name, while scripts stored in separate files cannot.
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. _class_Resource_property_resource_path:
  141. .. rst-class:: classref-property
  142. :ref:`String<class_String>` **resource_path** = ``""`` :ref:`🔗<class_Resource_property_resource_path>`
  143. .. rst-class:: classref-property-setget
  144. - |void| **set_path**\ (\ value\: :ref:`String<class_String>`\ )
  145. - :ref:`String<class_String>` **get_path**\ (\ )
  146. The unique path to this resource. If it has been saved to disk, the value will be its filepath. If the resource is exclusively contained within a scene, the value will be the :ref:`PackedScene<class_PackedScene>`'s filepath, followed by a unique identifier.
  147. \ **Note:** Setting this property manually may fail if a resource with the same path has already been previously loaded. If necessary, use :ref:`take_over_path()<class_Resource_method_take_over_path>`.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_Resource_property_resource_scene_unique_id:
  151. .. rst-class:: classref-property
  152. :ref:`String<class_String>` **resource_scene_unique_id** :ref:`🔗<class_Resource_property_resource_scene_unique_id>`
  153. .. rst-class:: classref-property-setget
  154. - |void| **set_scene_unique_id**\ (\ value\: :ref:`String<class_String>`\ )
  155. - :ref:`String<class_String>` **get_scene_unique_id**\ (\ )
  156. A unique identifier relative to the this resource's scene. If left empty, the ID is automatically generated when this resource is saved inside a :ref:`PackedScene<class_PackedScene>`. If the resource is not inside a scene, this property is empty by default.
  157. \ **Note:** When the :ref:`PackedScene<class_PackedScene>` is saved, if multiple resources in the same scene use the same ID, only the earliest resource in the scene hierarchy keeps the original ID. The other resources are assigned new IDs from :ref:`generate_scene_unique_id()<class_Resource_method_generate_scene_unique_id>`.
  158. \ **Note:** Setting this property does not emit the :ref:`changed<class_Resource_signal_changed>` signal.
  159. \ **Warning:** When setting, the ID must only consist of letters, numbers, and underscores. Otherwise, it will fail and default to a randomly generated ID.
  160. .. rst-class:: classref-section-separator
  161. ----
  162. .. rst-class:: classref-descriptions-group
  163. Method Descriptions
  164. -------------------
  165. .. _class_Resource_private_method__get_rid:
  166. .. rst-class:: classref-method
  167. :ref:`RID<class_RID>` **_get_rid**\ (\ ) |virtual| |const| :ref:`🔗<class_Resource_private_method__get_rid>`
  168. Override this method to return a custom :ref:`RID<class_RID>` when :ref:`get_rid()<class_Resource_method_get_rid>` is called.
  169. .. rst-class:: classref-item-separator
  170. ----
  171. .. _class_Resource_private_method__reset_state:
  172. .. rst-class:: classref-method
  173. |void| **_reset_state**\ (\ ) |virtual| :ref:`🔗<class_Resource_private_method__reset_state>`
  174. For resources that store state in non-exported properties, such as via :ref:`Object._validate_property()<class_Object_private_method__validate_property>` or :ref:`Object._get_property_list()<class_Object_private_method__get_property_list>`, this method must be implemented to clear them.
  175. .. rst-class:: classref-item-separator
  176. ----
  177. .. _class_Resource_private_method__set_path_cache:
  178. .. rst-class:: classref-method
  179. |void| **_set_path_cache**\ (\ path\: :ref:`String<class_String>`\ ) |virtual| |const| :ref:`🔗<class_Resource_private_method__set_path_cache>`
  180. Override this method to execute additional logic after :ref:`set_path_cache()<class_Resource_method_set_path_cache>` is called on this object.
  181. .. rst-class:: classref-item-separator
  182. ----
  183. .. _class_Resource_private_method__setup_local_to_scene:
  184. .. rst-class:: classref-method
  185. |void| **_setup_local_to_scene**\ (\ ) |virtual| :ref:`🔗<class_Resource_private_method__setup_local_to_scene>`
  186. Override this method to customize the newly duplicated resource created from :ref:`PackedScene.instantiate()<class_PackedScene_method_instantiate>`, if the original's :ref:`resource_local_to_scene<class_Resource_property_resource_local_to_scene>` is set to ``true``.
  187. \ **Example:** Set a random ``damage`` value to every local resource from an instantiated scene:
  188. ::
  189. extends Resource
  190. var damage = 0
  191. func _setup_local_to_scene():
  192. damage = randi_range(10, 40)
  193. .. rst-class:: classref-item-separator
  194. ----
  195. .. _class_Resource_method_duplicate:
  196. .. rst-class:: classref-method
  197. :ref:`Resource<class_Resource>` **duplicate**\ (\ deep\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`🔗<class_Resource_method_duplicate>`
  198. Duplicates this resource, returning a new resource with its ``export``\ ed or :ref:`@GlobalScope.PROPERTY_USAGE_STORAGE<class_@GlobalScope_constant_PROPERTY_USAGE_STORAGE>` properties copied from the original.
  199. If ``deep`` is ``false``, a **shallow** copy is returned: nested :ref:`Array<class_Array>`, :ref:`Dictionary<class_Dictionary>`, and **Resource** properties are not duplicated and are shared with the original resource.
  200. If ``deep`` is ``true``, a **deep** copy is returned: all nested arrays, dictionaries, and packed arrays are also duplicated (recursively). Any **Resource** found inside will only be duplicated if it's local, like :ref:`DEEP_DUPLICATE_INTERNAL<class_Resource_constant_DEEP_DUPLICATE_INTERNAL>` used with :ref:`duplicate_deep()<class_Resource_method_duplicate_deep>`.
  201. The following exceptions apply:
  202. - Subresource properties with the :ref:`@GlobalScope.PROPERTY_USAGE_ALWAYS_DUPLICATE<class_@GlobalScope_constant_PROPERTY_USAGE_ALWAYS_DUPLICATE>` flag are always duplicated (recursively or not, depending on ``deep``).
  203. - Subresource properties with the :ref:`@GlobalScope.PROPERTY_USAGE_NEVER_DUPLICATE<class_@GlobalScope_constant_PROPERTY_USAGE_NEVER_DUPLICATE>` flag are never duplicated.
  204. \ **Note:** For custom resources, this method will fail if :ref:`Object._init()<class_Object_private_method__init>` has been defined with required parameters.
  205. \ **Note:** When duplicating with ``deep`` set to ``true``, each resource found, including the one on which this method is called, will be only duplicated once and referenced as many times as needed in the duplicate. For instance, if you are duplicating resource A that happens to have resource B referenced twice, you'll get a new resource A' referencing a new resource B' twice.
  206. .. rst-class:: classref-item-separator
  207. ----
  208. .. _class_Resource_method_duplicate_deep:
  209. .. rst-class:: classref-method
  210. :ref:`Resource<class_Resource>` **duplicate_deep**\ (\ deep_subresources_mode\: :ref:`DeepDuplicateMode<enum_Resource_DeepDuplicateMode>` = 1\ ) |const| :ref:`🔗<class_Resource_method_duplicate_deep>`
  211. Duplicates this resource, deeply, like :ref:`duplicate()<class_Resource_method_duplicate>`\ ``(true)``, with extra control over how subresources are handled.
  212. \ ``deep_subresources_mode`` must be one of the values from :ref:`DeepDuplicateMode<enum_Resource_DeepDuplicateMode>`.
  213. .. rst-class:: classref-item-separator
  214. ----
  215. .. _class_Resource_method_emit_changed:
  216. .. rst-class:: classref-method
  217. |void| **emit_changed**\ (\ ) :ref:`🔗<class_Resource_method_emit_changed>`
  218. Emits the :ref:`changed<class_Resource_signal_changed>` signal. This method is called automatically for some built-in resources.
  219. \ **Note:** For custom resources, it's recommended to call this method whenever a meaningful change occurs, such as a modified property. This ensures that custom :ref:`Object<class_Object>`\ s depending on the resource are properly updated.
  220. ::
  221. var damage:
  222. set(new_value):
  223. if damage != new_value:
  224. damage = new_value
  225. emit_changed()
  226. .. rst-class:: classref-item-separator
  227. ----
  228. .. _class_Resource_method_generate_scene_unique_id:
  229. .. rst-class:: classref-method
  230. :ref:`String<class_String>` **generate_scene_unique_id**\ (\ ) |static| :ref:`🔗<class_Resource_method_generate_scene_unique_id>`
  231. Generates a unique identifier for a resource to be contained inside a :ref:`PackedScene<class_PackedScene>`, based on the current date, time, and a random value. The returned string is only composed of letters (``a`` to ``y``) and numbers (``0`` to ``8``). See also :ref:`resource_scene_unique_id<class_Resource_property_resource_scene_unique_id>`.
  232. .. rst-class:: classref-item-separator
  233. ----
  234. .. _class_Resource_method_get_id_for_path:
  235. .. rst-class:: classref-method
  236. :ref:`String<class_String>` **get_id_for_path**\ (\ path\: :ref:`String<class_String>`\ ) |const| :ref:`🔗<class_Resource_method_get_id_for_path>`
  237. From the internal cache for scene-unique IDs, returns the ID of this resource for the scene at ``path``. If there is no entry, an empty string is returned. Useful to keep scene-unique IDs the same when implementing a VCS-friendly custom resource format by extending :ref:`ResourceFormatLoader<class_ResourceFormatLoader>` and :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`.
  238. \ **Note:** This method is only implemented when running in an editor context. At runtime, it returns an empty string.
  239. .. rst-class:: classref-item-separator
  240. ----
  241. .. _class_Resource_method_get_local_scene:
  242. .. rst-class:: classref-method
  243. :ref:`Node<class_Node>` **get_local_scene**\ (\ ) |const| :ref:`🔗<class_Resource_method_get_local_scene>`
  244. If :ref:`resource_local_to_scene<class_Resource_property_resource_local_to_scene>` is set to ``true`` and the resource has been loaded from a :ref:`PackedScene<class_PackedScene>` instantiation, returns the root :ref:`Node<class_Node>` of the scene where this resource is used. Otherwise, returns ``null``.
  245. .. rst-class:: classref-item-separator
  246. ----
  247. .. _class_Resource_method_get_rid:
  248. .. rst-class:: classref-method
  249. :ref:`RID<class_RID>` **get_rid**\ (\ ) |const| :ref:`🔗<class_Resource_method_get_rid>`
  250. Returns the :ref:`RID<class_RID>` of this resource (or an empty RID). Many resources (such as :ref:`Texture2D<class_Texture2D>`, :ref:`Mesh<class_Mesh>`, and so on) are high-level abstractions of resources stored in a specialized server (:ref:`DisplayServer<class_DisplayServer>`, :ref:`RenderingServer<class_RenderingServer>`, etc.), so this function will return the original :ref:`RID<class_RID>`.
  251. .. rst-class:: classref-item-separator
  252. ----
  253. .. _class_Resource_method_is_built_in:
  254. .. rst-class:: classref-method
  255. :ref:`bool<class_bool>` **is_built_in**\ (\ ) |const| :ref:`🔗<class_Resource_method_is_built_in>`
  256. Returns ``true`` if the resource is saved on disk as a part of another resource's file.
  257. .. rst-class:: classref-item-separator
  258. ----
  259. .. _class_Resource_method_reset_state:
  260. .. rst-class:: classref-method
  261. |void| **reset_state**\ (\ ) :ref:`🔗<class_Resource_method_reset_state>`
  262. Makes the resource clear its non-exported properties. See also :ref:`_reset_state()<class_Resource_private_method__reset_state>`. Useful when implementing a custom resource format by extending :ref:`ResourceFormatLoader<class_ResourceFormatLoader>` and :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`.
  263. .. rst-class:: classref-item-separator
  264. ----
  265. .. _class_Resource_method_set_id_for_path:
  266. .. rst-class:: classref-method
  267. |void| **set_id_for_path**\ (\ path\: :ref:`String<class_String>`, id\: :ref:`String<class_String>`\ ) :ref:`🔗<class_Resource_method_set_id_for_path>`
  268. In the internal cache for scene-unique IDs, sets the ID of this resource to ``id`` for the scene at ``path``. If ``id`` is empty, the cache entry for ``path`` is cleared. Useful to keep scene-unique IDs the same when implementing a VCS-friendly custom resource format by extending :ref:`ResourceFormatLoader<class_ResourceFormatLoader>` and :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`.
  269. \ **Note:** This method is only implemented when running in an editor context.
  270. .. rst-class:: classref-item-separator
  271. ----
  272. .. _class_Resource_method_set_path_cache:
  273. .. rst-class:: classref-method
  274. |void| **set_path_cache**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_Resource_method_set_path_cache>`
  275. Sets the resource's path to ``path`` without involving the resource cache. Useful for handling :ref:`CacheMode<enum_ResourceFormatLoader_CacheMode>` values when implementing a custom resource format by extending :ref:`ResourceFormatLoader<class_ResourceFormatLoader>` and :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`.
  276. .. rst-class:: classref-item-separator
  277. ----
  278. .. _class_Resource_method_setup_local_to_scene:
  279. .. rst-class:: classref-method
  280. |void| **setup_local_to_scene**\ (\ ) :ref:`🔗<class_Resource_method_setup_local_to_scene>`
  281. **Deprecated:** This method should only be called internally.
  282. Calls :ref:`_setup_local_to_scene()<class_Resource_private_method__setup_local_to_scene>`. If :ref:`resource_local_to_scene<class_Resource_property_resource_local_to_scene>` is set to ``true``, this method is automatically called from :ref:`PackedScene.instantiate()<class_PackedScene_method_instantiate>` by the newly duplicated resource within the scene instance.
  283. .. rst-class:: classref-item-separator
  284. ----
  285. .. _class_Resource_method_take_over_path:
  286. .. rst-class:: classref-method
  287. |void| **take_over_path**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_Resource_method_take_over_path>`
  288. Sets the :ref:`resource_path<class_Resource_property_resource_path>` to ``path``, potentially overriding an existing cache entry for this path. Further attempts to load an overridden resource by path will instead return this resource.
  289. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  290. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  291. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  292. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  293. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  294. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  295. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  296. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  297. .. |void| replace:: :abbr:`void (No return value.)`