What does serialize mean?

Seriously.
I’ve searched the help files, and I’ve searched the forums, and I see a lot of mention of serialization, and not once can I get a clear idea of what it actually is. I’m reading through the 2D Platformer sample code to learn more about how it’s programmed, and the @System.NonSerialized line pops up frequently, but it’s not self explanatory like most commands are.

The help file gives me the useful definition of “The NonSerialized attribute marks a variable to not be serialized.”. Thanks for that. That clears it all up for me. :roll:

Maybe it’s important, maybe it’s not. I have no idea, because none of the tutorials or help files I’ve seen tell me anything!

If something is serializable, it can be turned into a stream of bits for storage:

If a variable is marked as NonSerialized, it won’t be included in the bit-stream. In other words, when the class is saved, that variable won’t be included.

In the context of Unity, serialization is important in that serializable objects will appear with all their members in the inspector and changes made in the inspector will be saved into the scene. NonSerialized variables will be excluded from that.

Thanks, that makes sense. :slight_smile:

This might sound like a stupid question, but does using the NonSerialized property for a variable make using private for that same variable redundant?

no it doesn’t
nonserialized has no impact on visibility etc, only on how data is stored when you serialize it.

if you wanted to hide something in the editor, there is a much better attribute for that than nonserialize / private, thats HideInEditor (± typos)

It seems to hide the variable in the inspector when I add @System.NonSerialized to the variable though. Now I’m confused. And what’s the different between HideInEditor and private?

nonserialize will hide it too yes.
Though it does more, cause it will also tell mono to not store the values you hold in there at all which can be of importance depending on what you do

private: Thats an access modifier. Private variables can be accessed by the class only, no other class using this one or talking to it.

HideInInspector: tells the inspector to ignore this field

Thanks for the help. That clears it up for me.

Thanks Dreamora and DlobVanDam. This thread help me to understand about serialize.