Function gdnative::globalscope::load

source ·
pub fn load<T>(path: impl Into<NodePath>) -> Option<Ref<T>>
where T: SubClass<Resource> + GodotObject<Memory = RefCounted>,
Expand description

Loads a resource from the filesystem located at path.

The resource is loaded on the method call (unless it’s referenced already elsewhere, e.g. in another script or in the scene), which might cause slight delay, especially when loading scenes.

If the resource cannot be loaded, or is not of type T or inherited, this method returns None.

This method is a simplified version of ResourceLoader::load(), which can be used for more advanced scenarios.

§Note:

Resource paths can be obtained by right-clicking on a resource in the Godot editor (FileSystem dock) and choosing “Copy Path”, or by dragging the file from the FileSystem dock into the script.

The path must be absolute (typically starting with res://), a local path will fail.

§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 gdnative::prelude::*;

let scene = load::<PackedScene>("res://path/to/Main.tscn").unwrap();