Moep Put the Testclass definition in its own source file named Testclass.cs

  • Moep replied to this.

    xyz

    I tried it and it results in the same error sadly.

    • xyz replied to this.

      Moep Are you sure? The filename is case-sensitive. It must be exactly the same as class name.

      • Moep replied to this.

        Moep Any reason you need to serialize by manually writing into a binary file instead of using a Resource-derived class that handles all that automatically?

        Can you provide, or link to an example of saving and restoring binary data using resources? I experimented with that, but couldn't figure it out.

        • xyz replied to this.

          DaveTheCoder Can you provide, or link to an example of saving and restoring binary data using resources? I experimented with that, but couldn't figure it out.

          Just save it as *.res instead of *.tres. ResourceSaver determines the format according to extension.

          class_name DeadParrot extends Resource
          var pushing_up_the_daisies = true;
          func _ready():
          	var polly = DeadParrot.new()
          	ResourceSaver.save(polly, "res://polly.res")
          	ResourceSaver.save(polly, "res://polly.tres")

          Regarding the OP. I tried to do the same in GDScript but also got some funky errors. Didn't have time to investigate further. Object serialization is always tricky so better play it safe and go with engine's preferred system - and that's resource objects/files.

          • Moep replied to this.

            xyz

            Yeah, for now i just serialize the properties one at a time with storevar() and then compose the class when loading back the simple property types.

            • xyz replied to this.

              Moep Yeah, for now i just serialize the properties one at a time with storevar() and then compose the class when loading back the simple property types.

              No need to do it like this. It's error prone, tedious and non-scalable. Simply inherit the class from Resource and use ResourceSaver.Save() and ResourceLoader.Load() to (de)serialize the object.

              • Moep replied to this.

                xyz

                I know that resources are the easiest to handle solution, but this is why i shy away from them for now https://github.com/godotengine/godot-proposals/issues/4925

                Also Godot provides an entire documentation page on saving and loading a game and binary serialization based on fA, so i don't think that resources are the one accepted/intended way to handle this.

                • xyz replied to this.

                  Moep Resources are not the only way. They are the easiest way though. The security problem is relevant only if you're handling user generated content shared between users.

                  Anyway, you should perhaps report this as an issue and see what happens, because it looks like it should work. I tried doing this in GDscript and it appears to be working in 3.5 but it's throwing class name shadowing error in 4.1