godotengine / godotengine/godot-docs

When should I use ResourceLoader.load type_hint?

Open
#10,436 0 comments 3 reactions 0 assignees View on GitHub
enhancement
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

**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](https://docs.godotengine.org/en/stable/classes/class_resource.html#class-resource) type that should be handled by the [ResourceFormatLoader](https://docs.godotengine.org/en/stable/classes/class_resourceformatloader.html#class-resourceformatloader). Anything that inherits from [Resource](https://docs.godotengine.org/en/stable/classes/class_resource.html#class-resource) can be used as a type hint, for example [Image](https://docs.godotengine.org/en/stable/classes/class_image.html#class-image).

From
https://github.com/godotengine/godot-docs/issues/1258#issuecomment-382364474 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:
```gdscript
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):
```
res://assets/audio/music/promises-111bpm.mp3
res://assets/audio/sfx/sfx_status_poison.wav
res://assets/textures/card_mask.png
res://assets/textures/you_win.png
res://assets/vfx/vfx_molotov.tscn
res://assets/materials/smoke_overlay_mat.tres
res://assets/materials/sky_mat.tres
res://assets/theme_hud.tres
res://assets/materials/smoke_overlay_shader.tres
```

The ResourceLoader.load docs also mention:

> GDScript has a simplified [@GDScript.load](https://docs.godotengine.org/en/stable/classes/class_%40gdscript.html#class-gdscript-method-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](https://docs.godotengine.org/en/stable/classes/class_resourceformatloader.html#class-resourceformatloader) to use when loading files outside a Godot project and the file type has multiple loaders. Anything that inherits from [Resource](https://docs.godotengine.org/en/stable/classes/class_resource.html#class-resource) can be used as a type hint, for example [Image](https://docs.godotengine.org/en/stable/classes/class_image.html#class-image).

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.