Struct PropertyInfo
pub struct PropertyInfo {
pub variant_type: VariantType,
pub class_id: ClassId,
pub property_name: StringName,
pub hint_info: PropertyHintInfo,
pub usage: PropertyUsageFlags,
}Expand description
Describes a property’s type, name and metadata for Godot.
PropertyInfo is used throughout the Godot binding to describe properties, method parameters and return types.
This is a high-level abstraction over the low-level FFI type sys::GDExtensionPropertyInfo. Unlike the FFI version which only stores
pointers, PropertyInfo owns its data, ensuring it remains valid for the lifetime of the struct.
See also MethodInfo for describing method signatures and ClassId for type-IDs of Godot classes.
§Construction
For most use cases, prefer the convenience constructors:
new_var::<T>()– creates property info for a#[var]attribute.new_export::<T>()– for an#[export]attribute.new_group()/new_subgroup()– for editor groups.
§Example
use godot::meta::{PropertyInfo, PropertyHintInfo, ClassId};
use godot::builtin::{StringName, VariantType};
use godot::global::PropertyUsageFlags;
// Integer property without a specific class
let count_property = PropertyInfo {
variant_type: VariantType::INT,
class_id: ClassId::none(), // Only OBJECT types need a real class ID.
property_name: StringName::from("count"),
hint_info: PropertyHintInfo::none(),
usage: PropertyUsageFlags::DEFAULT,
};Here, class_id is set to ClassId::none() because integer properties do not require a specific class. For objects, you can use
ClassId::new_cached::<T>(...) if you have a Rust type, or ClassId::new_dynamic(...)
for dynamic contexts and script classes.
Fields§
§variant_type: VariantTypeType of the property.
For objects, this should be set to VariantType::OBJECT and use the class_id field to specify the actual class.
For generic Variant properties, use VariantType::NIL.
class_id: ClassIdThe specific class identifier for object-typed properties in Godot.
This is only relevant when variant_type is set to VariantType::OBJECT.
§Example
use godot::meta::ClassId;
use godot::classes::Node3D;
use godot::obj::GodotClass; // Trait method ::class_id().
let none_id = ClassId::none(); // For built-ins (not classes).
let static_id = Node3D::class_id(); // For classes with a Rust type.
let dynamic_id = ClassId::new_dynamic("MyScript"); // For runtime class names.property_name: StringNameThe name of this property as it appears in Godot’s object system.
hint_info: PropertyHintInfoAdditional type information and validation constraints for this property.
Use functions from export_info_functions to create common hints,
or PropertyHintInfo::none() for no hints.
See PropertyHintInfo struct in Rust, as well as PropertyHint in the official Godot documentation.
usage: PropertyUsageFlagsFlags controlling how this property should be used and displayed by the Godot engine.
Common values:
PropertyUsageFlags::DEFAULT– standard property (readable, writable, saved, appears in editor).PropertyUsageFlags::STORAGE– persisted, but not shown in editor.PropertyUsageFlags::EDITOR– shown in editor, but not persisted.
See also PropertyUsageFlags in the official Godot documentation for a complete list of flags.
Implementations§
§impl PropertyInfo
impl PropertyInfo
pub fn new_var<T>(property_name: &str) -> PropertyInfowhere
T: Var,
pub fn new_var<T>(property_name: &str) -> PropertyInfowhere
T: Var,
Create a new PropertyInfo representing a property named property_name with type T automatically.
This will generate property info equivalent to what a #[var] attribute would produce.
pub fn new_export<T>(property_name: &str) -> PropertyInfowhere
T: Export,
pub fn new_export<T>(property_name: &str) -> PropertyInfowhere
T: Export,
Create a new PropertyInfo for an exported property named property_name with type T automatically.
This will generate property info equivalent to what an #[export] attribute would produce.
pub fn with_hint_info(self, hint_info: PropertyHintInfo) -> PropertyInfo
pub fn with_hint_info(self, hint_info: PropertyHintInfo) -> PropertyInfo
Change the hint and hint_string to be the given hint_info.
See export_info_functions for functions that return appropriate PropertyHintInfos for
various Godot annotations.
§Example
Creating an @export_range property.
use godot::register::property::export_info_functions;
use godot::meta::PropertyInfo;
let property = PropertyInfo::new_export::<f64>("my_range_property")
.with_hint_info(export_info_functions::export_range(
0.0,
10.0,
Some(0.1),
false,
false,
false,
false,
false,
false,
Some("mm".to_string()),
));pub fn new_group(group_name: &str, group_prefix: &str) -> PropertyInfo
pub fn new_group(group_name: &str, group_prefix: &str) -> PropertyInfo
Create a new PropertyInfo representing a group in Godot.
See EditorInspector in Godot for
more information.
pub fn new_subgroup(subgroup_name: &str, subgroup_prefix: &str) -> PropertyInfo
pub fn new_subgroup(subgroup_name: &str, subgroup_prefix: &str) -> PropertyInfo
Create a new PropertyInfo representing a subgroup in Godot.
See EditorInspector in Godot for
more information.
Trait Implementations§
§impl Clone for PropertyInfo
impl Clone for PropertyInfo
§fn clone(&self) -> PropertyInfo
fn clone(&self) -> PropertyInfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more