valantonini / AStar

A 2D A Star (A*) pathfinding implementation in C# focused on ease of use

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non serializable

Lurler opened this issue · 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.

Hi @Lurler,

That makes sense. Just some clarifications:

cheers,

val

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.

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.

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.

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?

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!

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.

@Lurler were you ever able to try this?

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.