General Category > Game Development

How are you handling Serialization with Unity3D?

<< < (2/10) > >>

x4000:

--- Quote from: RogueDeus on September 20, 2011, 05:49:13 PM ---Thanks for the swift replies.
--- End quote ---

Sure thing.


--- Quote from: RogueDeus on September 20, 2011, 05:49:13 PM ---So in AVWW when you enter an area with persisted data, you check to see if serialization has already occurred for that data, and if so you retrieve it?
--- End quote ---

Pretty much.  And if it's not there, then we generate it at that time, and then flag it to be saved when the program feels like it has time to.


--- Quote from: RogueDeus on September 20, 2011, 05:49:13 PM ---I am wondering about serialization mostly because it is the most mysterious part of coding for me.

--- End quote ---

There's nothing that magic about it; it's like writing notes to yourself on paper, and then remembering where the notes are.  You only look at the notes when you need the info they have, and you only write to the notes when something actually changes and you don't want to keep the info in your head anymore (for fear of forgetting, or because you want to think about something else now).

RogueDeus:

--- Quote from: x4000 on September 20, 2011, 05:51:32 PM ---
--- Quote from: RogueDeus on September 20, 2011, 05:49:13 PM ---So in AVWW when you enter an area with persisted data, you check to see if serialization has already occurred for that data, and if so you retrieve it?
--- End quote ---

Pretty much.  And if it's not there, then we generate it at that time, and then flag it to be saved when the program feels like it has time to.

--- End quote ---

Do you cache it in an array and manipulate it there till its written?


Most of the mystery for me is in when where and how to (de)serialize stuff. The whole idea of starting a game, as a movement of data, I get. But restoring the movement from a serialized state often turns my brain inside out for some odd reason.

x4000:
We don't use an array, no.  Usually.  The answer actually varies a bit.

If we have things that no longer need to be in memory but which need to be written to disk "at some point soon before they are dropped from memory," then we'll stick that in a generic list (in C# parlance).  Then the game can write from that list at its leisure, and remove the items as it goes.  That's very easy to throttle.

For other things, when determining what to write, it's usually just a bool on the object.  Then something else checks the bools on all the objects every so often, and writes the ones to disk that are flagged.  This also is easy to throttle if you have to, although slightly harder.

RogueDeus:

--- Quote from: x4000 on September 20, 2011, 06:07:37 PM ---We don't use an array, no.  Usually.  The answer actually varies a bit.

If we have things that no longer need to be in memory but which need to be written to disk "at some point soon before they are dropped from memory," then we'll stick that in a generic list (in C# parlance).  Then the game can write from that list at its leisure, and remove the items as it goes.  That's very easy to throttle.

For other things, when determining what to write, it's usually just a bool on the object.  Then something else checks the bools on all the objects every so often, and writes the ones to disk that are flagged.  This also is easy to throttle if you have to, although slightly harder.

--- End quote ---

By generic I guess you mean by 'type'? If so that is one of the other mysterious parts of coding for me. I have not quite digested generic type coding yet... :( Or reflection for that matter. (Though I want too!!)

Thanks for the info. As always you are great at feedback!

x4000:
Generics have a specific meaning in C#, which is different from type.  It's basically just a way of having a single "generic class" that inserts other types in place of the generic notation to make it as efficient as if you coded out the generic class once for each specific instance of the class.  So you don't get boxing and unboxing, etc.  And you don't need a ListOfInts class, or a ListOfGameObjects class.  You just have List<int> and List<GameObject> and that's that.  Much better than in the old days before generics.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version