What is the Different Between SerializeField and Public in Unity


 

Public Variables: Accessible and visible everywhere, no [SerializeField] needed, default values can be set.


Example:




public int myPublicVariable = 42;

SerializeField Variables: Exposed in the Inspector but maintain access control (private or protected), need [SerializeField] attribute, default values can be set.


Example:



[SerializeField] private int mySerializedField = 42;



 

Happy coding


Previous Post Next Post

Contact Form