Skip to content

Add retrieval methods to ResourceLoader for querying cached resource paths (C++, C#, GDScript) #13523

@TruelyMostWanted

Description

@TruelyMostWanted

Describe the project you are working on

Any game, tool or plugin, utilizing externally and internally located Resources that get loaded at runtime

Describe the problem or limitation you are having in your project

Cached Resources (= assigned to any (export) variables or attributes) are internally stored in the ResourceCache's HashMap<string, Ref<Resource>> resources in the form of { Key: "res://icon.svg/", Value: CompressedTexture2D() }
This API is not exposed in all 3 languages ( C++, C#, GDScript) and you can't filter the cached resource paths.
We should extend the ResourceLoader to access the caching system.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

SELECT ALL PATHS WHERE

  • TARGET { TypeHint, Path, FileName, FileExtension, BaseDir, ResourceName, ResourcePath, ResourceClass }
  • COMPARATOR { Equals, NotEquals, BeginsWith, EndsWith, Contains }
  • VALUE (String)

Examples:

get_all_cached_paths()
get_cached_paths_by_filter(target: TYPE_HINT, comparator: EQUALS, value: "Image")
get_cached_paths_by_filter(target: PATH, comparator: BEGINS_WITH, value: "res://")
get_cached_paths_by_filter(target: FILE_NAME, comparator: BEGINS_WITH, value: "Spritesheet_") 
get_cached_paths_by_filter(target: FILE_EXTENSION, comparator: EQUALS, value: "png") 
get_cached_paths_by_filter(target: FILE_EXTENSION, comparator: BEGINS_WITH, value: "t")

"TYPE_HINT" Values: { Image, AudioStreamWAV, PackedScene, JSON, Shader, StandardMaterial3D, ... }
"PATH" (Prefix, Substring) Examples: { "res://", "user://", "/data", "/materials", "/data/audio/", ... }
"FILE_NAME" (Prefix) Examples: { "Spritesheet_", "IMG_", "Sprite_" }
"FILE_EXTENSION" (Substring) Examples: { "tres", "res", "mp3", "wav", "ogg", "jpeg", "png", "json", "csv" "cs", "gd", .... }

Results have the form of:

  • Array = [path1, path2, path3, path4, path5, path6]
  • Dictionary { "Path1"="TypeHint1", "Path2"="TypeHint2" }

Then these informations can be used to load the specific resources over the ResourceLoader.load(path, typeHint, useWorkerThreads, CacheMode) method --> No breaking changes to existing logic

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

ResourceCache:

  • 2 templates for Predicates with 1 method each will be added to the resource_cache

ResourceLoader:

  • 2 Enums will be created for the FilterTarget and the FilterComparator
  • 4 additional methods will be declared and defined allowing to retrieve
    • all paths (as array + as dictionary)
    • all paths where the filter matches (as array + as dictionary)

Core_Bind:

  • Enums and Methods will be registered and exposed to GDScript and C#

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, as the ResourceCache API is not exposed at all.

Yes as users would need to create their own caching and managing systems, requiring to write basically "duplicated code" compared to the already existing ResourceLoader / ResourceCache inside the Godot Source Code.

Is there a reason why this should be core and not an add-on in the asset library?

These methods are particularly useful for retrieval queries in games, editor plugins, asset management tools, and runtime inspection and debugging.

Implementation

godotengine/godot#112217

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions