Open IceReaper opened 1 year ago
Variant
is a struct so indeed you can't return null. The marshaling code expects to receive a Variant
so it can communicate with Godot. It may be possible to support Variant?
but that would be a breaking change because this is just syntax sugar for System.Nullable<Variant>
which is a different type and changnig the return type of a method breaks compatibility.
What you actually need to do here is create a Variant
that represents null. You can do this by using the default
keyword or the parameterless constructor:
public override Variant _GetDragData(Vector2 atPosition)
{
return default;
}
Godot version
4.0.3
System information
Windows 11, Godot 4.0.3, Vulkan
Issue description
Control docs state:
Variant _get_drag_data ( Vector2 at_position ) virtual const
Godot calls this method to get data that can be dragged and dropped onto controls that expect drop data. Returns null if there is no data to drag.
However, using a c# project
I cannot return null in this function, as its return type is defined as
Variant
, and notVariant?
Compilation error is[CS0037] Cannot convert null to 'Variant' because it is a non-nullable value type
Steps to reproduce
Minimal reproduction project
N/A