Skip to main content

PropertyInfo

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:

§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: VariantType

Type 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: StringName

The 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: StringName

The name of this property as it appears in Godot’s object system.

§hint_info: PropertyHintInfo

Additional 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: PropertyUsageFlags

Flags controlling how this property should be used and displayed by the Godot engine.

Common values:

See also PropertyUsageFlags in the official Godot documentation for a complete list of flags.

Implementations§

§

impl PropertyInfo

pub fn new_var<T>(property_name: &str) -> PropertyInfo
where 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) -> PropertyInfo
where 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

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

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

Create a new PropertyInfo representing a subgroup in Godot.

See EditorInspector in Godot for more information.

Trait Implementations§

§

impl Clone for PropertyInfo

§

fn clone(&self) -> PropertyInfo

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for PropertyInfo

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.