Question on SerializeField?
Hi there, I have a doubt that how to use SerializeField in our script. I know when you kept serializeField to a private variable it forces to serialize and we can see that variable in the inspector. Doc: https://docs.unity3d.com/ScriptReference/SerializeField.html
But my doubt is how cost it is while using. I Mean I have 40 to 50 Variables that I need assign in the inspector. for that using public variable is the best practice or serializeField is best.
Answer by Vollmondum · Mar 29, 2019 at 01:09 PM
[SerializeField] is something useless unless you have 10000+ variables and targeting some museum-worth computers. People use it because they were taught so :) SF means turning your variable with its value into 1byte, to clear some memory, nothing more. Delete all of it. P.S. There will probably be those who's strongly disagreed. Disregard those people, they're blind beyond books they read in college (probably like 2000 edition XD)
Thanks for your reply. Ok, I transfer all serializableField variable to the public. but Am in the confusion that why I need put public to a variable where am not accessing those variable in any other script only to assign in the inspector.
[SerializeField] is something useless unless you have 10000+ variables and targeting some museum-worth computers.
I strongly disagree. Having SerializeField
attribute forces the variable to be serialized by Unity, even if the variable is not declared as public
. When the variable is public
, Unity serializes the variable automatically, so the overhead of the attribute may be very small compared to one of the fundamentals of Object-Oriented-Program$$anonymous$$g : Encapsulation) . The best way to find out is to profile, but this is micro-optimization I$$anonymous$$HO.
SF means turning your variable with its value into 1byte, to clear some memory, nothing more
Could you provide the source of this information please? I really don't see how it could be possible to store any complex variable into one byte.