Home > Mobile >  SerializeField vs public, will this cause problems later?
SerializeField vs public, will this cause problems later?

Time:12-07

So I was looking back on some of my stuff here, and I noticed that I was using a lot of [SerializeField], instead of public. I like to do this so I can see exactly what's what when I actually start testing this stuff out. However, I haven't gotten very far in my project, and I'm still learning as I go, but was wondering if this overuse of [SerializeField] might cause problems later. So, my question is: Will using serialize field instead of public cause any problems if I use it a lot?

CodePudding user response:

Serialization is the process of taking an object in ram (classes, fields, etc...) and making a disk representation of it which can be recreated at any point in the future. When you apply the SerializeField attribute to a field, it tells the unity engine to save/restore it's state to/from disk. You mostly use serialization for the editor, and especially when building your own editor windows and inspectors.

For most games (especially simple ones) PlayerPrefs is sufficient for saving state to disk.

Note: this was something I found on google https://forum.unity.com/threads/when-to-use-serializefield-and-why.184687/

My own note, if you really not going to use your own inspector then using SerializeField may decrease some of the performance.

  • Related