Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When should I use ResourceLoader.load type_hint? #10436

Open
idbrii opened this issue Dec 21, 2024 · 0 comments
Open

When should I use ResourceLoader.load type_hint? #10436

idbrii opened this issue Dec 21, 2024 · 0 comments

Comments

@idbrii
Copy link
Contributor

idbrii commented Dec 21, 2024

Your Godot version: 4.3

Issue description:

It's unclear when I would use the type_hint parameter to ResourceLoader.load. The current text only explains how:

An optional type_hint can be used to further specify the Resource type that should be handled by the ResourceFormatLoader. Anything that inherits from Resource can be used as a type hint, for example Image.

From
#1258 (comment) it sounds like I need it to resolve resolution when the loader is ambiguous:

I think type hint is used when there are file collisions for the extension format. Like obj or bin, programmer might add multiple loaders which means that godot will be confused which ever works. Having a hint would help godot choose the correct loader.

From that I assume that I otherwise don't need to pass it and there's no benefits to passing it?

I wrote a test to try importing a bunch of types of files:

for f in files:
    var r = ResourceLoader.load(f) as Resource
    printt(r, f)

And the output makes it seem like it imported them correctly (it even uses the correctly png import type that I'd already setup):

<AudioStreamMP3#-9223370035953599644>	res://assets/audio/music/promises-111bpm.mp3
<AudioStreamWAV#-9223370031742518365>	res://assets/audio/sfx/sfx_status_poison.wav
<BitMap#-9223370220939185519>	res://assets/textures/card_mask.png
<CompressedTexture2D#-9223370016592692126>	res://assets/textures/you_win.png
<PackedScene#-9223370013958669101>	res://assets/vfx/vfx_molotov.tscn
<ShaderMaterial#-9223370030383563865>	res://assets/materials/smoke_overlay_mat.tres
<StandardMaterial3D#-9223370038587622591>	res://assets/materials/sky_mat.tres
<Theme#-9223370208222055709>	res://assets/theme_hud.tres
<VisualShader#-9223370030635222072>	res://assets/materials/smoke_overlay_shader.tres

The ResourceLoader.load docs also mention:

GDScript has a simplified @GDScript.load built-in method which can be used in most situations, leaving the use of ResourceLoader for more advanced scenarios.

So I suspect this type_hint is intended for loading files from the user's disk and not from within a godot project (where you should use load()).

Possibly the string could be:

An optional type_hint can be used to indicate which ResourceFormatLoader to use when loading files outside a Godot project and the file type has multiple loaders. Anything that inherits from Resource can be used as a type hint, for example Image.

URL to the documentation page (if already existing):
https://docs.godotengine.org/en/stable/classes/class_resourceloader.html#class-resourceloader-method-load

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant