get_autoload_by_name

Function get_autoload_by_name 

pub fn get_autoload_by_name<T>(autoload_name: &str) -> Gd<T>
where T: Inherits<Node>,
Expand description

Retrieves an autoload by name.

See Godot docs for an explanation of the autoload concept. Godot sometimes uses the term “autoload” interchangeably with “singleton”; we strictly refer to the former to separate from Singleton objects.

If the autoload can be resolved, it will be cached and returned very quickly the second time.

§Panics

This is a convenience function that calls try_get_autoload_by_name(). Panics if that fails, e.g. not found or wrong type.

§Example

use godot::prelude::*;
use godot::tools::get_autoload_by_name;

#[derive(GodotClass)]
#[class(init, base=Node)]
struct GlobalStats {
    base: Base<Node>,
}

// Assuming "Statistics" is registered as an autoload in `project.godot`,
// this returns the one instance of type Gd<GlobalStats>.
let stats = get_autoload_by_name::<GlobalStats>("Statistics");