Creating a GDExtension type with an exported Resource property that defaults to something other than null causes the Godot editor to use a specific, static instance of that type as the default value to revert that property.
That means it's possible to modify the default, so that reverting behaves in unexpected ways. Same behavior as #36372.
In particular, this makes it very tricky to implement non-null properties in GDExtension types. For example, a custom transform type that has a useful default value and is cheap to construct. Or something like Path2D from #36372 but instead of reverting to null it reverts to an empty path. For the Rust GDExtension bindings in particular this would be very nice to avoid null checks all over the code base.
Steps to reproduce
Create a GDExtension type with an exported Curve2D property that defaults to Curve2D.new() in init
Follow the repro steps in #36372 :
Draw your curve.
Now press the reset button. Curve disappears, but when you now draw a new curve, the reset button is also gone.
If you select "New Curve2D" from the dropdown, and then reset, it will default to the previous curve you had drawn.
Godot version
4.1.1
System information
Ubuntu 22.04.3
Issue description
See also #36372 and https://github.com/godot-rust/gdext/issues/440
Creating a GDExtension type with an exported
Resource
property that defaults to something other than null causes the Godot editor to use a specific, static instance of that type as the default value to revert that property.That means it's possible to modify the default, so that reverting behaves in unexpected ways. Same behavior as #36372.
In particular, this makes it very tricky to implement non-null properties in GDExtension types. For example, a custom transform type that has a useful default value and is cheap to construct. Or something like Path2D from #36372 but instead of reverting to null it reverts to an empty path. For the Rust GDExtension bindings in particular this would be very nice to avoid null checks all over the code base.
Steps to reproduce
Curve2D
property that defaults toCurve2D.new()
ininit
Example video with the attached repro project:
godot-obj-nonnull-repro.webm
Minimal reproduction project
obj-nonnull-repro.zip
To build the GDExtension lib: