class_resourceloader.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/ResourceLoader.xml.
  6. .. _class_ResourceLoader:
  7. ResourceLoader
  8. ==============
  9. **Inherits:** :ref:`Object<class_Object>`
  10. Singleton used to load resource files.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Singleton used to load resource files from the filesystem.
  15. It uses the many :ref:`ResourceFormatLoader<class_ResourceFormatLoader>` classes registered in the engine (either built-in or from a plugin) to load files into memory and convert them to a format that can be used by the engine.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - `OS Test Demo <https://godotengine.org/asset-library/asset/677>`__
  20. .. rst-class:: classref-reftable-group
  21. Methods
  22. -------
  23. .. table::
  24. :widths: auto
  25. +-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`bool<class_bool>` | :ref:`exists<class_ResourceLoader_method_exists>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` type_hint="" **)** |
  27. +-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`get_dependencies<class_ResourceLoader_method_get_dependencies>` **(** :ref:`String<class_String>` path **)** |
  29. +-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`get_recognized_extensions_for_type<class_ResourceLoader_method_get_recognized_extensions_for_type>` **(** :ref:`String<class_String>` type **)** |
  31. +-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`bool<class_bool>` | :ref:`has<class_ResourceLoader_method_has>` **(** :ref:`String<class_String>` path **)** |
  33. +-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`bool<class_bool>` | :ref:`has_cached<class_ResourceLoader_method_has_cached>` **(** :ref:`String<class_String>` path **)** |
  35. +-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`Resource<class_Resource>` | :ref:`load<class_ResourceLoader_method_load>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` type_hint="", :ref:`bool<class_bool>` no_cache=false **)** |
  37. +-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`ResourceInteractiveLoader<class_ResourceInteractiveLoader>` | :ref:`load_interactive<class_ResourceLoader_method_load_interactive>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` type_hint="", :ref:`bool<class_bool>` no_cache=false **)** |
  39. +-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | void | :ref:`set_abort_on_missing_resources<class_ResourceLoader_method_set_abort_on_missing_resources>` **(** :ref:`bool<class_bool>` abort **)** |
  41. +-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. .. rst-class:: classref-section-separator
  43. ----
  44. .. rst-class:: classref-descriptions-group
  45. Method Descriptions
  46. -------------------
  47. .. _class_ResourceLoader_method_exists:
  48. .. rst-class:: classref-method
  49. :ref:`bool<class_bool>` **exists** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` type_hint="" **)**
  50. Returns whether a recognized resource exists for the given ``path``.
  51. An optional ``type_hint`` can be used to further specify the :ref:`Resource<class_Resource>` type that should be handled by the :ref:`ResourceFormatLoader<class_ResourceFormatLoader>`.
  52. .. rst-class:: classref-item-separator
  53. ----
  54. .. _class_ResourceLoader_method_get_dependencies:
  55. .. rst-class:: classref-method
  56. :ref:`PoolStringArray<class_PoolStringArray>` **get_dependencies** **(** :ref:`String<class_String>` path **)**
  57. Returns the dependencies for the resource at the given ``path``.
  58. .. rst-class:: classref-item-separator
  59. ----
  60. .. _class_ResourceLoader_method_get_recognized_extensions_for_type:
  61. .. rst-class:: classref-method
  62. :ref:`PoolStringArray<class_PoolStringArray>` **get_recognized_extensions_for_type** **(** :ref:`String<class_String>` type **)**
  63. Returns the list of recognized extensions for a resource type.
  64. .. rst-class:: classref-item-separator
  65. ----
  66. .. _class_ResourceLoader_method_has:
  67. .. rst-class:: classref-method
  68. :ref:`bool<class_bool>` **has** **(** :ref:`String<class_String>` path **)**
  69. *Deprecated method.* Use :ref:`has_cached<class_ResourceLoader_method_has_cached>` or :ref:`exists<class_ResourceLoader_method_exists>` instead.
  70. .. rst-class:: classref-item-separator
  71. ----
  72. .. _class_ResourceLoader_method_has_cached:
  73. .. rst-class:: classref-method
  74. :ref:`bool<class_bool>` **has_cached** **(** :ref:`String<class_String>` path **)**
  75. Returns whether a cached resource is available for the given ``path``.
  76. Once a resource has been loaded by the engine, it is cached in memory for faster access, and future calls to the :ref:`load<class_ResourceLoader_method_load>` or :ref:`load_interactive<class_ResourceLoader_method_load_interactive>` methods will use the cached version. The cached resource can be overridden by using :ref:`Resource.take_over_path<class_Resource_method_take_over_path>` on a new resource for that same path.
  77. .. rst-class:: classref-item-separator
  78. ----
  79. .. _class_ResourceLoader_method_load:
  80. .. rst-class:: classref-method
  81. :ref:`Resource<class_Resource>` **load** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` type_hint="", :ref:`bool<class_bool>` no_cache=false **)**
  82. Loads a resource at the given ``path``, caching the result for further access.
  83. The registered :ref:`ResourceFormatLoader<class_ResourceFormatLoader>`\ s are queried sequentially to find the first one which can handle the file's extension, and then attempt loading. If loading fails, the remaining ResourceFormatLoaders are also attempted.
  84. An optional ``type_hint`` can be used to further specify the :ref:`Resource<class_Resource>` type that should be handled by the :ref:`ResourceFormatLoader<class_ResourceFormatLoader>`. Anything that inherits from :ref:`Resource<class_Resource>` can be used as a type hint, for example :ref:`Image<class_Image>`.
  85. If ``no_cache`` is ``true``, the resource cache will be bypassed, and the resource will be loaded anew. Otherwise, the cached resource will be returned if it exists.
  86. Returns an empty resource if no :ref:`ResourceFormatLoader<class_ResourceFormatLoader>` could handle the file.
  87. GDScript has a simplified :ref:`@GDScript.load<class_@GDScript_method_load>` built-in method which can be used in most situations, leaving the use of **ResourceLoader** for more advanced scenarios.
  88. .. rst-class:: classref-item-separator
  89. ----
  90. .. _class_ResourceLoader_method_load_interactive:
  91. .. rst-class:: classref-method
  92. :ref:`ResourceInteractiveLoader<class_ResourceInteractiveLoader>` **load_interactive** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` type_hint="", :ref:`bool<class_bool>` no_cache=false **)**
  93. Starts loading a resource interactively. The returned :ref:`ResourceInteractiveLoader<class_ResourceInteractiveLoader>` object allows to load with high granularity, calling its :ref:`ResourceInteractiveLoader.poll<class_ResourceInteractiveLoader_method_poll>` method successively to load chunks.
  94. An optional ``type_hint`` can be used to further specify the :ref:`Resource<class_Resource>` type that should be handled by the :ref:`ResourceFormatLoader<class_ResourceFormatLoader>`. Anything that inherits from :ref:`Resource<class_Resource>` can be used as a type hint, for example :ref:`Image<class_Image>`.
  95. If ``no_cache`` is ``true``, the resource cache will be bypassed, and the resource will be loaded anew. Otherwise, the cached resource will be returned if it exists.
  96. .. rst-class:: classref-item-separator
  97. ----
  98. .. _class_ResourceLoader_method_set_abort_on_missing_resources:
  99. .. rst-class:: classref-method
  100. void **set_abort_on_missing_resources** **(** :ref:`bool<class_bool>` abort **)**
  101. Changes the behavior on missing sub-resources. The default behavior is to abort loading.
  102. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  103. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  104. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  105. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`