What is the difference between [SerializeField] and public?
For example;
[SerializeField] int num1 = 0;
and
public int num1 = 0;
They both give the same output, controls in the Unity inspector tab, so what is the difference between them?
What is the difference between [SerializeField] and public?
For example;
[SerializeField] int num1 = 0;
and
public int num1 = 0;
They both give the same output, controls in the Unity inspector tab, so what is the difference between them?
Great question!
You’re right that they both make the variable visible in the inspector. The big difference is that, over on the coding side, the serialized field you’ve set up is still a private variable - so you won’t be able to directly access it from other scripts.
When setting the access levels for your variables your really asking two questions, do I want to:
I hope that helps.
Yes, thank you!
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.