Struct PropertyInfo
pub struct PropertyInfo {
pub variant_type: VariantType,
pub class_name: StringName,
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 the Rust representation of the FFI type sys::GDExtensionPropertyInfo, still relatively low level. Unlike the FFI version which
only stores pointers, PropertyInfo owns its data, ensuring it remains valid for the lifetime of the struct.
For a high-level representation of properties, see GodotShape.
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};
use godot::builtin::{StringName, VariantType};
use godot::global::PropertyUsageFlags;
// Integer property without a specific class
let count_property = PropertyInfo {
variant_type: VariantType::INT,
class_name: StringName::default(), // Only OBJECT types and enums need a real class/enum name.
property_name: StringName::from("count"),
hint_info: PropertyHintInfo::none(),
usage: PropertyUsageFlags::DEFAULT,
};For OBJECT types, class_name should be set to the class name (e.g., "Node3D"). You can use GodotClass::class_id() +
ClassId::to_string_name() to keep this type-safe across class renames.
If the property refers to an enum, class_name should be set to the enum name (e.g., "Node.ProcessMode" or "GlobalEnum").
User-defined enums can also be registered with the empty string (they’re a loose list of enumerators in that case).
Fields§
§variant_type: VariantTypeType of the property.
For objects, this should be set to VariantType::OBJECT and use the class_name field to specify the actual class.
For enums, this should be set to VariantType::INT and use the class_name field to specify the enum name.
For generic Variant properties, use VariantType::NIL.
class_name: StringNameThe specific class or enum name for object-typed and enum properties in Godot.
Assign the following value:
- For objects (
variant_type == OBJECT), this should be set to the class name (e.g.,"Node3D","RefCounted"). - For enums (commonly
variant_type == INT), this should be set to the enum name (e.g.,"Node.ProcessMode"or"GlobalEnum"). Rust-side enums that aren’t registered with Godot can also use the empty string – in that case it’s a loose list of enumerators. - For other types, this should be left empty, i.e.
StringName::default().
§Example
use godot::builtin::StringName;
use godot::classes::Node3D;
use godot::meta::ClassId;
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.
// Convert to StringName for this field:
let class_name = static_id.to_string_name();
// Or directly, without caching the class name globally (recommended anyway for enums):
let class_name = StringName::from("MyScript");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: the property is accessible
from GDScript but not shown in the editor and not saved. Uses PropertyUsageFlags::NONE as base usage.
For editor-visible + saved properties, use new_export().
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: the property is shown
in the editor and saved. Uses PropertyUsageFlags::DEFAULT as base usage.
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