What's the difference between [SerializeField] and public?

I’ve been going through the course and I already have some basic C# and Unity knowledge, but this [SerializeField] is new to me. The teacher says it’s to be able to change the values in the Unity Editor, but public does the same thing. Is it just a to-may-to/to-mah-to difference?

2 Likes

You don’t always want fields to be public. Some fields should not be access from outside the class. But you may want to change them in the editor. That is what SerializeField does for you. Your field can be private, but still editable in the inspector

4 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms