How to create a `Variant` with value `null` in `C#`? For overriding godot methods

Godot Version

4.3-mono

Question

I want to return a null of GDScript in C#, and I can only use Variant as the return value.
So how to return a Variant contains a null.

    public override Variant _PropertyGetRevert(StringName property)
    {
        return null; // this throws a compilation error, how to fix it?
        // In fact, it will only return null when it's in some specified conditions.
    }

I have read the C# Variant Documentation but I have found nothing related that.
Thanks very much.

Look what I found in the Godot docs here

I quote:

Since the Variant type in C# is a struct, it can’t be null. To create a “null” Variant, use the default keyword or the Godot.Variant parameterless constructor.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.