Open
Description
Accessing Gd<Self>
pointer in constructors silently crashes the editor.
I haven't dug too deep into the library implementation so I'm not sure if this is a bug or a constructor API design limitation, but considering that WithBaseField::to_gd
is part of the public API and the equivalent C++ and GDScript code works fine I thought I'd mention it.
Minimal example:
#[derive(GodotClass)]
#[class(base=Object)]
struct MyObject {
base: Base<Object>,
}
#[godot_api]
impl IObject for MyObject {
fn init(base: Base<Object>) -> Self {
let instance = Self { base };
instance.to_gd(); // <-- crash (downcast panic)
instance
}
}
The intended use case was to connect some local signals in the constructor while building a custom editor plugin, which seems to be a common pattern in engine code. This requires Gd<Self>
for constructing a callable via Callable::from_object_method(&instance.to_gd(), "method_name")
.
EDIT: Removed "silent" since it was an unrelated issue