Function try_load_threaded
pub async fn try_load_threaded<T>(
path: impl AsArg<GString>,
) -> Result<Gd<T>, IoError>Available on crate feature
experimental-threads only.Expand description
Loads a resource from the filesystem located at path on a worker thread.
This function can fail if resource can’t be loaded by ResourceLoader or if the subsequent cast into T fails.
This method is a simplified version of ResourceLoader::load_threaded_request,
which can be used for more advanced scenarios.
See synchronous version try_load() for more details.
§Example
Loads a scene called Main located in the path/to subdirectory of the Godot project and caches it in a variable.
The resource is directly stored with type PackedScene.
use godot::prelude::*;
godot::task::spawn(async {
if let Ok(scene) = try_load_threaded::<PackedScene>("res://path/to/Main.tscn").await {
// all good
} else {
// handle error
}
});