Hello everyone!
Im trying to serialize my custom class in godot in c#. Everything works fine unless i try to get data back as a custom class.
Here is a code snippet.
public partial class GodotSerilisationTest : Node
{
public override void _Ready()
{
FileAccess fa = FileAccess.Open("user://test.sav", FileAccess.ModeFlags.Write);
string test = "mytestdata";
Testclass testclass = new Testclass("sometestclass");
fa.StoreVar(test, true);
fa.StoreVar("Anotehr Test", true);
fa.StoreVar(testclass, true);
fa.Dispose();
fa = FileAccess.Open("user://test.sav", FileAccess.ModeFlags.Read);
var foo = fa.GetVar(true);
var foo2 = fa.GetVar(true);
//ERRROR
var foo3 = fa.GetVar(true);
GD.Print(foo);
GD.Print(foo2);
if (foo3.AsGodotObject() is Testclass bar)
{
GD.Print(bar.teststring);
}
fa.Dispose();
}
}
public partial class Testclass : GodotObject
{
public string teststring;
public Testclass(string teststring)
{
this.teststring = teststring;
}
}
It throws the following error:
E 0:00:00:0786 Godot.NativeInterop.NativeFuncs.generated.cs:345 @ void Godot.NativeInterop.NativeFuncs.godotsharp_method_bind_ptrcall(IntPtr , IntPtr , System.Void** , System.Void* ): Cannot instance script because the associated class could not be found. Script: ''. Make sure the script exists and contains a class definition with a name that matches the filename of the script exactly (it's case-sensitive).
<C++ Error> Method/function failed. Returning: false
<C++ Source> modules/mono/csharp_script.cpp:2388 @ can_instantiate()
<Stack Trace> Godot.NativeInterop.NativeFuncs.generated.cs:345 @ void Godot.NativeInterop.NativeFuncs.godotsharp_method_bind_ptrcall(IntPtr , IntPtr , System.Void** , System.Void* )
NativeCalls.cs:3710 @ Godot.Variant Godot.NativeCalls.godot_icall_1_432(IntPtr , IntPtr , Godot.NativeInterop.godot_bool )
FileAccess.cs:485 @ Godot.Variant Godot.FileAccess.GetVar(Boolean )
GodotSerilisationTest.cs:20 @ void GodotSerilisationTest._Ready()
Node.cs:2093 @ Boolean Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
GodotSerilisationTest_ScriptMethods.generated.cs:24 @ Boolean GodotSerilisationTest.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(IntPtr , Godot.NativeInterop.godot_string_name* , Godot.NativeInterop.godot_variant** , Int32 , Godot.NativeInterop.godot_variant_call_error* , Godot.NativeInterop.godot_variant* )
If someone has a pointer on why this is happening let me know.