AStar icon indicating copy to clipboard operation
AStar copied to clipboard

Non serializable

Open Lurler opened this issue 3 years ago • 9 comments

Greetings.

Can you consider marking your classes as serializable? I instantiate the grid and pathfinder inside the game map object, so when I want to save the map with a binary serializer I'm unable to do so due to the classes not being marked as such.

It would simplify things massively if you can make it serializable, rather than me trying to concoct some kind of proxy and store pathfinder for each map separately and regenerating them after map loading or switching.

Regards.

Lurler avatar Sep 18 '22 13:09 Lurler

Hi @Lurler,

That makes sense. Just some clarifications:

cheers,

val

valantonini avatar Sep 19 '22 07:09 valantonini

Thank you for the quick reply. Let me try to explain in details.

Is it just the world grid that needs binary serialization? All classes that are part of object hierarchy need to be marked as [Serializable] for that to work. In my case WorldGrid and PathFinder are both inside of the map object, so they and any other objects that are instantiated or used/referenced inside them must be also marked as such.

Does the game map serializer use the [SerializableAttribute](https://learn.microsoft.com/en-us/dotnet/api/system.serializableattribute?view=net-6.0) to serialize its children (the WorldGrid) as per [making an object serializable](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/serialization/#making-an-object-serializable) Yes, I simply use binary serializer for now. I may consider alternative approaches, but that's what I use for now.

Lurler avatar Sep 19 '22 09:09 Lurler

Makes sense, I'll have a look at it this week.

Did you get it from nuget? If so, i can publish a prerelease package with the change for you to test.

valantonini avatar Sep 19 '22 12:09 valantonini

Yes, from nuget.

If you'd like me to test the experimental package just let me know and I will pull it and see if everything works.

Lurler avatar Sep 19 '22 12:09 Lurler

Hi @Lurler,

I've started work on a branch. I noticed when writing the test that a few of the binary serialization APIs are deprecated. I've only every binary serialized using protobuf, is this unit test using the correct serialize/deserialize api?

valantonini avatar Sep 25 '22 22:09 valantonini

Hm, I was not aware of that. I remember using it back in the day, so I just reused the same code. I guess it is a good point. If this serialization approach is deprecated then it might not be a good idea to support it in the long run or encourage bad practices, I guess. In that case I will just search for an alternative serialization solution. Thanks!

Lurler avatar Sep 29 '22 02:09 Lurler

It's no problem, the game engine may not necessarily be using that serialization method. I pushed up a beta version of the package to nuget with the serialization support. See if it fixes your issue.

valantonini avatar Sep 29 '22 04:09 valantonini

@Lurler were you ever able to try this?

valantonini avatar Feb 19 '23 13:02 valantonini

Sorry for late reply. I did try the native serialization, but in the end I decided to use a different serialization approach as it's more robust and would work with any package, even if it's not setup for serialization.

Lurler avatar Feb 20 '23 00:02 Lurler