godot-rust / gdnative

Rust bindings for Godot 3
https://godot-rust.github.io
MIT License
3.61k stars 210 forks source link

Exporting a property with Option doesn't seem to allow for a nullable type #903

Closed setzer22 closed 1 year ago

setzer22 commented 2 years ago

I have the following struct:

#[derive(NativeClass)]
#[inherit(gd::Node)]
pub struct MyNodeType {
    // Allows setting a custom resource from the inspector
    #[property]
    pub some_prop: Option<Ref<Resource>>,
}

When this is instanced, I can see the exported property in the Godot editor, and I can also set values as expected. The initial value is shown as "empty", so the field is correctly being initialized to None and returned as null on the Godot side.

However, when I have set the value for it and click "Clear" from the inspector, I get the following error:

ERROR: Incorrect type passed to property: expected non-nullable type, got null
   at: <unset> (/home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/gdnative-core-0.10.0/src/export/property/accessor.rs:250)
Bogay commented 2 years ago

@setzer22 Which version of godot-rust did you use? I can't reproduce it on v0.10.1, on WSL.

setzer22 commented 2 years ago

I was on 0.10.0, I will try to reproduce on newer versions :+1:

chitoyuu commented 1 year ago

Recently a bug was discovered that caused Option::<Ref<T>>::from_variant to incorrectly return Err when passed a null object variant value. This was since fixed in #1002. From the description of the issue it looks like this would've been fixed as well.

Closing for now, but feel free to re-open if you're still experiencing this in 0.11.2!