godotengine / godotengine/godot-dotnet
Marshalling is not supported for the type - GodotArray<T>
- Dominant language
- C#
- Stars
- 228
- Forks
- 30
- PR merge metrics
- No merged PRs in 30d
Description
### Godot version
4.5 Beta 2
### Godot .NET packages version
4.5 Dev (937f0c5)
### System information
Windows 11
### .NET information
Version 9.0.2
### Issue description
When using a `GodotArray` with a `[GodotClass]` and a `[BindProperty]` (it's the same for the dictionary) :
```c#
[BindProperty] public GodotArray TestCollection { get; set; }
```
I get the following error :
```c#
Unhandled exception. System.InvalidOperationException: Marshalling is not supported for the type 'Godot.Collections.GodotArray`1[[System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'.
at Godot.NativeInterop.Marshalling.ThrowUnsupportedType[T]() + 0x48
at Godot.NativeInterop.Marshalling.ThrowUnsupportedTypeIfNull[T](Void*) + 0x1b
at Godot.NativeInterop.Marshalling.GenericConversion`1.ConvertToVariant(T&) + 0x32
at Godot.NativeInterop.Marshalling.ConvertToVariant[T](T&) + 0x168
at Godot.Bridge.MethodBindInvoker.g__TrampolineWithVariantArgs|22_1[TInstance,TResult](MethodInfo, GodotObject, Delegate, NativeGodotVariantPtrSpan, NativeGodotVariant&) + 0x6f
at Godot.Bridge.ClassRegistrationContext.CallWithVariantArgs_Native(Void*, Void*, NativeGodotVariant**, Int64, NativeGodotVariant*, GDExtensionCallError*) + 0xc0
```
From what I can see, this code is not called when initializing an extension :
```c#
static unsafe GodotArray()
{
Marshalling.GenericConversion>.AssignToPtrCb = &WriteUnmanagedFunc;
Marshalling.GenericConversion>.FromPtrCb = &ConvertFromUnmanagedFunc;
Marshalling.GenericConversion>.ToVariantCb = &ConvertToVariantFunc;
Marshalling.GenericConversion>.FromVariantCb = &ConvertFromVariantFunc;
}
```
Which make the `ToVariantCb` function undefined.
If I call a new Array before to register my class, this works because the static function is called, but this is a workaround :
```c#
// This makes the register work because the static function that registers the Func is called
var array = new GodotArray();
GodotRegistry.RegisterInternalClass(TestAddonPlugin.BindMethods);
```
I'd be happy to contribute if needed, I'm just not quite sure where to start.
### Steps to reproduce
- Create a new dotnet project
- Link the GodotDotnet library with nuget
- Create the entry point
- Create a class that has a `[BindProperty] public GodotArray TestCollection { get; set; }`
- Register the class using something like `GodotRegistry.RegisterInternalClass(TestAddonPlugin.BindMethods);`
- Publish the project and run it as a GDExtension with Godot
- The error should occur
### Minimal reproduction project
I can provide one if needed but I think the steps are quite simple.
Contributor guide
Research direction
Start with the GodotArray static constructor and its GenericConversion callback assignments, then reproduce the issue using a [BindProperty] GodotArray during GodotRegistry.RegisterInternalClass. Done means the ToVariant callback is registered before the bound property is marshalled, without constructing a GodotArray as a workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, godot
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100