Godot: C# Exporting variables not working when Nullable is used

Created on 1 Jul 2018  路  7Comments  路  Source: godotengine/godot

When writing a script in C# and exporting a Nullable variable the exported variable doesn't appear in the Godot editor.
To reproduce:

  1. create a node in your scene
  2. add a script to it
  3. add the following variable to your class:
    C# [Export] public float _testVariable; [Export] public Nullable<float> _testVariable2;

After you do some magic for the exported variable to appear in the Godot Inspector (mainly rebuilding the project) you will see that _testVariable appears in the Godot Inspector but _testVariable2 does not.

About the versions i am using:
Godot 3.0.4.stable.mono.official.916135
macOS High Sierra 10.13.4

Sorry if this is duplicated just couldn't find it.

Thank you,
Blake

enhancement mono

Most helpful comment

Still here on 3.1-beta3.
The problem is Nullable<T> is not marshallable so that's a wider issue than exporting properties.

E.g.
We had a bit of a hard time debugging #25499 through Discord.
The following code was raising marshalling errors.

private void SpawnRock(int size, Vector2? pos = null, Vector2? velocity = null)
{
    ...
}

private void _on_Rock_Boom(int size, float radius, Vector2 pos, Vector2 vel)
{
    ...
    CallDeferred("SpawnRock", size - 1, pos, vel);
    ...
}

That's because when actually calling the SpawnRock method, the Vector2s couldn't be marshalled back to what the method is expecting: Vector2? (i.e. Nullable<Vector2>).

All 7 comments

Still here on 3.1-beta3.
The problem is Nullable<T> is not marshallable so that's a wider issue than exporting properties.

E.g.
We had a bit of a hard time debugging #25499 through Discord.
The following code was raising marshalling errors.

private void SpawnRock(int size, Vector2? pos = null, Vector2? velocity = null)
{
    ...
}

private void _on_Rock_Boom(int size, float radius, Vector2 pos, Vector2 vel)
{
    ...
    CallDeferred("SpawnRock", size - 1, pos, vel);
    ...
}

That's because when actually calling the SpawnRock method, the Vector2s couldn't be marshalled back to what the method is expecting: Vector2? (i.e. Nullable<Vector2>).

I do not use C# in Godot, but Unity, for example, forces you now to use = default on every SerializeField variables and other situations, this may be similar here.

Well, it does not exactly _force_ but spams annoying warnings which is the same :upside_down_face: .

No, we just don't handle this type yet. I'm working on a PR :slightly_smiling_face:

Still valid as of 3.2 beta 5 Mono, following the steps in OP. This error is printed:

ERROR: _get_member_export: Unknown exported member type: 'Main._testVariable2'.
   At: modules/mono/csharp_script.cpp:2469.

I'll try to get this done for 3.2, but I will prioritize bugs. If I can't get this in time, it will be moved to 4.0 and cherry-picked into 3.2.1.

Moving to the next milestone as even if I implement this now, it's too late to include it in 3.2.0 stable. It will be cherry-picked in 3.2.1.

It may be related, so i'm adding this here; that custom classes/objects are also not exported properly, meaning fields of custom classes (those implicitly deriving from System.Object).

Was this page helpful?
0 / 5 - 0 ratings