You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Trait for user-defined singleton classes in Godot.
689
+
///
690
+
/// Implementing this trait allows accessing a registered singleton instance through [`singleton()`][Singleton::singleton].
691
+
/// User singletons should be registered under their class name – otherwise some Godot components (for example GDScript before 4.4) might have trouble handling them,
692
+
/// and the editor might crash when using `T::singleton()`.
693
+
///
694
+
/// There should be only one instance of a given singleton class in the engine, valid as long as the library is loaded.
695
+
/// Therefore, user singletons are limited to classes with manual memory management (ones not inheriting from `RefCounted`).
696
+
///
697
+
/// # Registration
698
+
///
699
+
/// Godot-rust provides a way to register given class as an Engine Singleton with [`#[class(singleton)]`](../prelude/derive.GodotClass.html#user-engine-singletons).
700
+
///
701
+
/// Alternatively, user singleton can be registered manually:
702
+
///
703
+
/// ```no_run
704
+
/// # use godot::prelude::*;
705
+
/// #[derive(GodotClass)]
706
+
/// #[class(init, base = Object)]
707
+
/// struct MyEngineSingleton {}
708
+
///
709
+
/// // Provides blanket implementation allowing to use MyEngineSingleton::singleton().
710
+
/// // Ensures that `MyEngineSingleton` is a valid singleton (i.e., a non-refcounted GodotClass).
711
+
/// impl UserSingleton for MyEngineSingleton {}
712
+
///
713
+
/// #[gdextension]
714
+
/// unsafe impl ExtensionLibrary for MyExtension {
0 commit comments