godot-rust / gdext

Rust bindings for Godot 4
https://mastodon.gamedev.place/@GodotRust
Mozilla Public License 2.0
2.98k stars 187 forks source link

#[var(set = `function_name`)] is not compatible with #[func(rename = `gdscript_name`)] #863

Open Houtamelo opened 4 weeks ago

Houtamelo commented 4 weeks ago

Example:

#[derive(GodotClass)]
#[class(init, base = CharacterBody2D)]
pub struct Herbivore {
    #[var(get, set = gdscript_set_health)]
    pub(super) health: f64,
}

#[godot_api]
impl Herbivore {
    #[func(rename = set_health)]
    fn gdscript_set_health(&mut self, value: f64) { 
        self.set_health(value);
    }
}

This compiles in Rust but in Godot we get a runtime error when trying to invoke the property: image

This happens because inside Godot its using the original name, not the renamed one.

Not sure if this is by design or a niche bug.

Bromeon commented 4 weeks ago

Interesting! Certainly not intended.

Might be a bit tricky because those are in two separate macros, and I don't know if the #[func(rename)] info is "stored" somewhere to be accessible by code generated from #[derive(Godot)]. It should be possible, but might require an extra indirection for each get/set function reference.