Skip to content

Communication with Godot

How do I export a Gd<T> field to the Godot editor?

Use the #[export] attribute on a field of type OnEditor<Gd<T>>(recommend) or Option<Gd<T>>.

#[derive(GodotClass)]
#[class(init, base = Node)]
struct Exporter {
#[export]
my_node: OnEditor<Gd<Node>>,
}

How do I call a GDScript method from Rust?

Use the Object::call()method on the Gd<T> instance representing the object whose method you want to call.

self.base_mut().call("method", &[]);
node.call("free", &[]);

How do I make a Rust method callable from GDScript?

Declare the method within an impl block annotated with #[godot_api]. Mark the specific function you want to expose with the #[func] attribute.

#[godot_api]
impl MyCallableClass {
#[func] // makes a function available to the Godot engine.
fn print_value() {
godot_print!("Hello");
}
}