class_resource.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Resource.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Resource:
  6. Resource
  7. ========
  8. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`Animation<class_Animation>`, :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:`BakedLightmapData<class_BakedLightmapData>`, :ref:`BitMap<class_BitMap>`, :ref:`ButtonGroup<class_ButtonGroup>`, :ref:`CryptoKey<class_CryptoKey>`, :ref:`CubeMap<class_CubeMap>`, :ref:`Curve<class_Curve>`, :ref:`Curve2D<class_Curve2D>`, :ref:`Curve3D<class_Curve3D>`, :ref:`DynamicFontData<class_DynamicFontData>`, :ref:`EditorSettings<class_EditorSettings>`, :ref:`EditorSpatialGizmoPlugin<class_EditorSpatialGizmoPlugin>`, :ref:`Environment<class_Environment>`, :ref:`Font<class_Font>`, :ref:`GDNativeLibrary<class_GDNativeLibrary>`, :ref:`GIProbeData<class_GIProbeData>`, :ref:`Gradient<class_Gradient>`, :ref:`Image<class_Image>`, :ref:`InputEvent<class_InputEvent>`, :ref:`Material<class_Material>`, :ref:`Mesh<class_Mesh>`, :ref:`MeshLibrary<class_MeshLibrary>`, :ref:`MultiMesh<class_MultiMesh>`, :ref:`NavigationMesh<class_NavigationMesh>`, :ref:`NavigationPolygon<class_NavigationPolygon>`, :ref:`OccluderPolygon2D<class_OccluderPolygon2D>`, :ref:`OpenSimplexNoise<class_OpenSimplexNoise>`, :ref:`PackedDataContainer<class_PackedDataContainer>`, :ref:`PackedScene<class_PackedScene>`, :ref:`PhysicsMaterial<class_PhysicsMaterial>`, :ref:`PolygonPathFinder<class_PolygonPathFinder>`, :ref:`RichTextEffect<class_RichTextEffect>`, :ref:`Script<class_Script>`, :ref:`Shader<class_Shader>`, :ref:`Shape<class_Shape>`, :ref:`Shape2D<class_Shape2D>`, :ref:`ShortCut<class_ShortCut>`, :ref:`Skin<class_Skin>`, :ref:`Sky<class_Sky>`, :ref:`SpriteFrames<class_SpriteFrames>`, :ref:`StyleBox<class_StyleBox>`, :ref:`TextFile<class_TextFile>`, :ref:`Texture<class_Texture>`, :ref:`TextureLayered<class_TextureLayered>`, :ref:`Theme<class_Theme>`, :ref:`TileSet<class_TileSet>`, :ref:`Translation<class_Translation>`, :ref:`VideoStream<class_VideoStream>`, :ref:`VisualScriptNode<class_VisualScriptNode>`, :ref:`VisualShaderNode<class_VisualShaderNode>`, :ref:`World<class_World>`, :ref:`World2D<class_World2D>`, :ref:`X509Certificate<class_X509Certificate>`
  10. Base class for all resources.
  11. Description
  12. -----------
  13. Resource is the base class for all Godot-specific resource types, serving primarily as data containers. Unlike :ref:`Object<class_Object>`\ s, they are reference-counted and freed when no longer in use. They are also cached once loaded from disk, so that any further attempts to load a resource from a given path will return the same reference (all this in contrast to a :ref:`Node<class_Node>`, which is not reference-counted and can be instanced from disk as many times as desired). Resources can be saved externally on disk or bundled into another object, such as a :ref:`Node<class_Node>` or another resource.
  14. Tutorials
  15. ---------
  16. - :doc:`../getting_started/step_by_step/resources`
  17. - :doc:`../getting_started/workflow/best_practices/node_alternatives`
  18. Properties
  19. ----------
  20. +-----------------------------+---------------------------------------------------------------------------------+-----------+
  21. | :ref:`bool<class_bool>` | :ref:`resource_local_to_scene<class_Resource_property_resource_local_to_scene>` | ``false`` |
  22. +-----------------------------+---------------------------------------------------------------------------------+-----------+
  23. | :ref:`String<class_String>` | :ref:`resource_name<class_Resource_property_resource_name>` | ``""`` |
  24. +-----------------------------+---------------------------------------------------------------------------------+-----------+
  25. | :ref:`String<class_String>` | :ref:`resource_path<class_Resource_property_resource_path>` | ``""`` |
  26. +-----------------------------+---------------------------------------------------------------------------------+-----------+
  27. Methods
  28. -------
  29. +---------------------------------+------------------------------------------------------------------------------------------------------------------+
  30. | void | :ref:`_setup_local_to_scene<class_Resource_method__setup_local_to_scene>` **(** **)** |virtual| |
  31. +---------------------------------+------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Resource<class_Resource>` | :ref:`duplicate<class_Resource_method_duplicate>` **(** :ref:`bool<class_bool>` subresources=false **)** |const| |
  33. +---------------------------------+------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Node<class_Node>` | :ref:`get_local_scene<class_Resource_method_get_local_scene>` **(** **)** |const| |
  35. +---------------------------------+------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`RID<class_RID>` | :ref:`get_rid<class_Resource_method_get_rid>` **(** **)** |const| |
  37. +---------------------------------+------------------------------------------------------------------------------------------------------------------+
  38. | void | :ref:`setup_local_to_scene<class_Resource_method_setup_local_to_scene>` **(** **)** |
  39. +---------------------------------+------------------------------------------------------------------------------------------------------------------+
  40. | void | :ref:`take_over_path<class_Resource_method_take_over_path>` **(** :ref:`String<class_String>` path **)** |
  41. +---------------------------------+------------------------------------------------------------------------------------------------------------------+
  42. Signals
  43. -------
  44. .. _class_Resource_signal_changed:
  45. - **changed** **(** **)**
  46. Emitted whenever the resource changes.
  47. Property Descriptions
  48. ---------------------
  49. .. _class_Resource_property_resource_local_to_scene:
  50. - :ref:`bool<class_bool>` **resource_local_to_scene**
  51. +-----------+---------------------------+
  52. | *Default* | ``false`` |
  53. +-----------+---------------------------+
  54. | *Setter* | set_local_to_scene(value) |
  55. +-----------+---------------------------+
  56. | *Getter* | is_local_to_scene() |
  57. +-----------+---------------------------+
  58. If ``true``, the resource will be made unique in each instance of its local scene. It can thus be modified in a scene instance without impacting other instances of that same scene.
  59. ----
  60. .. _class_Resource_property_resource_name:
  61. - :ref:`String<class_String>` **resource_name**
  62. +-----------+-----------------+
  63. | *Default* | ``""`` |
  64. +-----------+-----------------+
  65. | *Setter* | set_name(value) |
  66. +-----------+-----------------+
  67. | *Getter* | get_name() |
  68. +-----------+-----------------+
  69. The name of the resource. This is an optional identifier.
  70. ----
  71. .. _class_Resource_property_resource_path:
  72. - :ref:`String<class_String>` **resource_path**
  73. +-----------+-----------------+
  74. | *Default* | ``""`` |
  75. +-----------+-----------------+
  76. | *Setter* | set_path(value) |
  77. +-----------+-----------------+
  78. | *Getter* | get_path() |
  79. +-----------+-----------------+
  80. The path to the resource. In case it has its own file, it will return its filepath. If it's tied to the scene, it will return the scene's path, followed by the resource's index.
  81. Method Descriptions
  82. -------------------
  83. .. _class_Resource_method__setup_local_to_scene:
  84. - void **_setup_local_to_scene** **(** **)** |virtual|
  85. Virtual function which can be overridden to customize the behavior value of :ref:`setup_local_to_scene<class_Resource_method_setup_local_to_scene>`.
  86. ----
  87. .. _class_Resource_method_duplicate:
  88. - :ref:`Resource<class_Resource>` **duplicate** **(** :ref:`bool<class_bool>` subresources=false **)** |const|
  89. Duplicates the resource, returning a new resource. By default, sub-resources are shared between resource copies for efficiency. This can be changed by passing ``true`` to the ``subresources`` argument which will copy the subresources.
  90. **Note:** If ``subresources`` is ``true``, this method will only perform a shallow copy. Nested resources within subresources will not be duplicated and will still be shared.
  91. ----
  92. .. _class_Resource_method_get_local_scene:
  93. - :ref:`Node<class_Node>` **get_local_scene** **(** **)** |const|
  94. If :ref:`resource_local_to_scene<class_Resource_property_resource_local_to_scene>` is enabled and the resource was loaded from a :ref:`PackedScene<class_PackedScene>` instantiation, returns the local scene where this resource's unique copy is in use. Otherwise, returns ``null``.
  95. ----
  96. .. _class_Resource_method_get_rid:
  97. - :ref:`RID<class_RID>` **get_rid** **(** **)** |const|
  98. Returns the RID of the resource (or an empty RID). Many resources (such as :ref:`Texture<class_Texture>`, :ref:`Mesh<class_Mesh>`, etc) are high-level abstractions of resources stored in a server, so this function will return the original RID.
  99. ----
  100. .. _class_Resource_method_setup_local_to_scene:
  101. - void **setup_local_to_scene** **(** **)**
  102. This method is called when a resource with :ref:`resource_local_to_scene<class_Resource_property_resource_local_to_scene>` enabled is loaded from a :ref:`PackedScene<class_PackedScene>` instantiation. Its behavior can be customized by overriding :ref:`_setup_local_to_scene<class_Resource_method__setup_local_to_scene>` from script.
  103. For most resources, this method performs no base logic. :ref:`ViewportTexture<class_ViewportTexture>` performs custom logic to properly set the proxy texture and flags in the local viewport.
  104. ----
  105. .. _class_Resource_method_take_over_path:
  106. - void **take_over_path** **(** :ref:`String<class_String>` path **)**
  107. Sets the path of the resource, potentially overriding an existing cache entry for this path. This differs from setting :ref:`resource_path<class_Resource_property_resource_path>`, as the latter would error out if another resource was already cached for the given path.
  108. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  109. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  110. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`