This is a somewhat more complicated question than it might appear.
Every Unity video and tutorial that discusses access modifiers that I can find tells me that "private
is the default access modifier for member variables in C#", but according to the C# documentation the default access modifier should be internal
.
- E.g., this official video, timestamped to the point where the speaker says this: https://youtu.be/_0oBLCJcpCs?t=224
- E.g., this question on Unity Answers where the approved answer says the default is
private
: https://answers.unity.com/questions/1252048/private-vs-no-access-modifier-c.html - E.g., this forum thread where the answerer says the default access modifier in C# is
private
and cites a documentation page that says otherwise! https://forum.unity.com/threads/c-method-access-modifer.156749/
So, the question is, what is the true story of what's going on here? If I don't put an access modifier on a variable in a unity script it does act private, but what is Unity doing to make this happen!? Somehow I cannot find an explanation online.
See also this unanswered question on Unity Answers.