- Home /
Private Serialized vs Public, The Actual Effect on a Game
Hello,
I'm speaking about code safety, here.
Before I continue, I've read many many many many sources describing exactly what it is to serialize a private or public variable. That is not what I'm confused about.
If you're coming to this question and you don't really know what I'm talking about:
Basics -- the script reference
Almost at my question -- but not quite
Further Explanation -- but still, not answering my question
These are just a few of the dozen that I read over the past couple of months...
I also know the difference between public and private variables.
What I do NOT know, is the difference between a private variable that can be accessed in the inspector versus a public variable.
By that, I mean I do not know the "safety" difference between using a serialized private or a public. Are serialized privates more prone to corruption?
Only difference I could point out is to prevent scripts from modifying something you want kept private, whilst still keeping it editable in-editor.
Answer by BlueRaja_2014 · Jun 28, 2013 at 07:02 PM
public
variables can have their values altered in code outside the class, private
variables cannot.
Serialized private
fields will still be read/written to when being serialized.
So, they are really two separate concepts. You should only make the private field serialized if you want its state saved when serializing the object onto the hard-drive/across the network, or you want its value editable within the editor.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Expose Private Field in Custom Editor 3 Answers
comparing variables of gameobjects in an array 2 Answers
Cram variables inside class, use inheritance, or something else? 1 Answer