class_resourceloader.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 ResourceLoader.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_ResourceLoader:
  6. ResourceLoader
  7. ==============
  8. **Inherits:** :ref:`Object<class_Object>`
  9. Singleton used to load resource files.
  10. Description
  11. -----------
  12. Singleton used to load resource files from the filesystem.
  13. 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.
  14. 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.
  15. Methods
  16. -------
  17. +---------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`bool<class_bool>` | :ref:`exists<class_ResourceLoader_method_exists>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` type_hint="" **)** |
  19. +---------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_dependencies<class_ResourceLoader_method_get_dependencies>` **(** :ref:`String<class_String>` path **)** |
  21. +---------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_recognized_extensions_for_type<class_ResourceLoader_method_get_recognized_extensions_for_type>` **(** :ref:`String<class_String>` type **)** |
  23. +---------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`bool<class_bool>` | :ref:`has_cached<class_ResourceLoader_method_has_cached>` **(** :ref:`String<class_String>` path **)** |
  25. +---------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :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 **)** |
  27. +---------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Resource<class_Resource>` | :ref:`load_threaded_get<class_ResourceLoader_method_load_threaded_get>` **(** :ref:`String<class_String>` path **)** |
  29. +---------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`ThreadLoadStatus<enum_ResourceLoader_ThreadLoadStatus>` | :ref:`load_threaded_get_status<class_ResourceLoader_method_load_threaded_get_status>` **(** :ref:`String<class_String>` path, :ref:`Array<class_Array>` progress=[ ] **)** |
  31. +---------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_threaded_request<class_ResourceLoader_method_load_threaded_request>` **(** :ref:`String<class_String>` path, :ref:`String<class_String>` type_hint="", :ref:`bool<class_bool>` use_sub_threads=false **)** |
  33. +---------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`set_abort_on_missing_resources<class_ResourceLoader_method_set_abort_on_missing_resources>` **(** :ref:`bool<class_bool>` abort **)** |
  35. +---------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. Enumerations
  37. ------------
  38. .. _enum_ResourceLoader_ThreadLoadStatus:
  39. .. _class_ResourceLoader_constant_THREAD_LOAD_INVALID_RESOURCE:
  40. .. _class_ResourceLoader_constant_THREAD_LOAD_IN_PROGRESS:
  41. .. _class_ResourceLoader_constant_THREAD_LOAD_FAILED:
  42. .. _class_ResourceLoader_constant_THREAD_LOAD_LOADED:
  43. enum **ThreadLoadStatus**:
  44. - **THREAD_LOAD_INVALID_RESOURCE** = **0** --- The resource is invalid, or has not been loaded with :ref:`load_threaded_request<class_ResourceLoader_method_load_threaded_request>`.
  45. - **THREAD_LOAD_IN_PROGRESS** = **1** --- The resource is still being loaded.
  46. - **THREAD_LOAD_FAILED** = **2** --- Some error occurred during loading and it failed.
  47. - **THREAD_LOAD_LOADED** = **3** --- The resource was loaded successfully and can be accessed via :ref:`load_threaded_get<class_ResourceLoader_method_load_threaded_get>`.
  48. Method Descriptions
  49. -------------------
  50. .. _class_ResourceLoader_method_exists:
  51. - :ref:`bool<class_bool>` **exists** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` type_hint="" **)**
  52. Returns whether a recognized resource exists for the given ``path``.
  53. 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>`.
  54. ----
  55. .. _class_ResourceLoader_method_get_dependencies:
  56. - :ref:`PackedStringArray<class_PackedStringArray>` **get_dependencies** **(** :ref:`String<class_String>` path **)**
  57. Returns the dependencies for the resource at the given ``path``.
  58. ----
  59. .. _class_ResourceLoader_method_get_recognized_extensions_for_type:
  60. - :ref:`PackedStringArray<class_PackedStringArray>` **get_recognized_extensions_for_type** **(** :ref:`String<class_String>` type **)**
  61. Returns the list of recognized extensions for a resource type.
  62. ----
  63. .. _class_ResourceLoader_method_has_cached:
  64. - :ref:`bool<class_bool>` **has_cached** **(** :ref:`String<class_String>` path **)**
  65. Returns whether a cached resource is available for the given ``path``.
  66. 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>` method 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.
  67. ----
  68. .. _class_ResourceLoader_method_load:
  69. - :ref:`Resource<class_Resource>` **load** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` type_hint="", :ref:`bool<class_bool>` no_cache=false **)**
  70. Loads a resource at the given ``path``, caching the result for further access.
  71. 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.
  72. 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>`.
  73. 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.
  74. Returns an empty resource if no ResourceFormatLoader could handle the file.
  75. ----
  76. .. _class_ResourceLoader_method_load_threaded_get:
  77. - :ref:`Resource<class_Resource>` **load_threaded_get** **(** :ref:`String<class_String>` path **)**
  78. Returns the resource loaded by :ref:`load_threaded_request<class_ResourceLoader_method_load_threaded_request>`.
  79. If this is called before the loading thread is done (i.e. :ref:`load_threaded_get_status<class_ResourceLoader_method_load_threaded_get_status>` is not :ref:`THREAD_LOAD_LOADED<class_ResourceLoader_constant_THREAD_LOAD_LOADED>`), the calling thread will be blocked until the resource has finished loading.
  80. ----
  81. .. _class_ResourceLoader_method_load_threaded_get_status:
  82. - :ref:`ThreadLoadStatus<enum_ResourceLoader_ThreadLoadStatus>` **load_threaded_get_status** **(** :ref:`String<class_String>` path, :ref:`Array<class_Array>` progress=[ ] **)**
  83. Returns the status of a threaded loading operation started with :ref:`load_threaded_request<class_ResourceLoader_method_load_threaded_request>` for the resource at ``path``. See :ref:`ThreadLoadStatus<enum_ResourceLoader_ThreadLoadStatus>` for possible return values.
  84. An array variable can optionally be passed via ``progress``, and will return a one-element array containing the percentage of completion of the threaded loading.
  85. ----
  86. .. _class_ResourceLoader_method_load_threaded_request:
  87. - :ref:`Error<enum_@GlobalScope_Error>` **load_threaded_request** **(** :ref:`String<class_String>` path, :ref:`String<class_String>` type_hint="", :ref:`bool<class_bool>` use_sub_threads=false **)**
  88. Loads the resource using threads. If ``use_sub_threads`` is ``true``, multiple threads will be used to load the resource, which makes loading faster, but may affect the main thread (and thus cause game slowdowns).
  89. ----
  90. .. _class_ResourceLoader_method_set_abort_on_missing_resources:
  91. - void **set_abort_on_missing_resources** **(** :ref:`bool<class_bool>` abort **)**
  92. Changes the behavior on missing sub-resources. The default behavior is to abort loading.