Struct MethodInfo
pub struct MethodInfo {
pub id: i32,
pub method_name: StringName,
pub class_name: ClassId,
pub return_type: PropertyInfo,
pub arguments: Vec<PropertyInfo>,
pub default_arguments: Vec<Variant>,
pub flags: MethodFlags,
}Expand description
Describes a method’s signature and metadata required by the Godot engine.
Primarily used when implementing custom script instances via the ScriptInstance trait.
It contains metadata Godot needs to describe and call a method.
MethodInfo is a high-level abstraction over the low-level FFI type sys::GDExtensionMethodInfo.
See also PropertyInfo for describing individual method parameters and return types.
§Example
use godot::meta::{MethodInfo, PropertyInfo, PropertyHintInfo, ClassId};
use godot::builtin::{StringName, Variant, VariantType};
use godot::global::{MethodFlags, PropertyUsageFlags};
use godot::classes::Node2D;
use godot::obj::GodotClass; // Trait method ::class_id().
// Describe a Godot method (`World` is a GDScript class):
// func spawn_at(world: World, position: Vector2) -> Node2D.
let method = MethodInfo {
id: 0,
method_name: StringName::from("spawn_at"),
class_name: ClassId::none(),
return_type: PropertyInfo {
variant_type: VariantType::OBJECT,
class_id: Node2D::class_id(),
property_name: StringName::default(), // Return types use empty string.
hint_info: PropertyHintInfo::none(),
usage: PropertyUsageFlags::DEFAULT,
},
arguments: vec![
PropertyInfo {
variant_type: VariantType::OBJECT,
class_id: ClassId::new_dynamic("World"),
property_name: StringName::from("world"),
hint_info: PropertyHintInfo::none(),
usage: PropertyUsageFlags::DEFAULT,
},
PropertyInfo {
variant_type: VariantType::VECTOR2,
class_id: ClassId::none(),
property_name: StringName::from("position"),
hint_info: PropertyHintInfo::none(),
usage: PropertyUsageFlags::DEFAULT,
},
],
default_arguments: vec![],
flags: MethodFlags::DEFAULT,
};Fields§
§id: i32Unique identifier for the method within its class.
This ID can be used to distinguish between methods and is typically set by the implementation. For script instances, this is often just a sequential index.
method_name: StringNameThe name of the method, as it appears in Godot.
class_name: ClassIdThe class this method belongs to.
For script-defined methods, this is typically the script’s class ID obtained via ClassId::new_dynamic().
Use ClassId::none() if the class is not applicable or unknown.
return_type: PropertyInfoDescription of the method’s return type.
See PropertyInfo for how to construct type information. For methods that
don’t return a value (void), use VariantType::NIL.
arguments: Vec<PropertyInfo>Descriptions of each method parameter.
Each element describes one parameter’s type, name, and metadata. The order matches the parameter order in the method signature.
default_arguments: Vec<Variant>Default values for parameters with defaults.
Contains the actual default Variant values for parameters that have them.
The length of this vector is typically less than or equal to arguments.len(),
containing defaults only for trailing parameters.
flags: MethodFlagsMethod flags controlling behavior and access.
See MethodFlags for available options like NORMAL, VIRTUAL, CONST, etc.
Trait Implementations§
§impl Clone for MethodInfo
impl Clone for MethodInfo
§fn clone(&self) -> MethodInfo
fn clone(&self) -> MethodInfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more