Where are the rules of capitalization documented?

Where are the rules of capitalization documented? I've seen guidelines list somewhere but didn't realise they were enforced.

I spent several hours bashing my head against an external script access issue until I worked out that the script name had to be capitalized (settingsManager didn't work but SettingsManager did).

Many thanks


In a nutshell, in C# or Unity's Javascript (unityscript), everything is case sensitive. For almost everthing*, the capitalization is the same for both C# and Javascript.

This includes:

  • Variables
  • Functions
  • Classes
  • Tags
  • Game Object names (as entered in the inspector)

For the rules of capitalization for Unity's own API (the classes and functions that are unique to Unity), simply see the Unity scripting reference. Documented there are every class, function and property which allow you specific control over unity objects and features.

For the rules of capitalization for the rest of the .NET api that you have available to you, the primary reference should be the MSDN C# reference (for .net 2.0). Even though this is C#, the capitalization of the Classes, Functions, Properties and Variables are all the same for Javascript.

For your own classes, functions and variable names (the ones you define in your script), you simply have to be consistent with your own chosen capitalisation. When using c# (or when explicitly writing out the class declaration in Javascript), you also need to ensure that your script file has the same name as the Monobehaviour class defined within.

While you have free reign in terms of naming your own things, there are certain conventions which - unless your have your on reasons not to - it's a good idea to use. It creates consistency within your own code and with other unity developers when sharing and using code on the forums and Wiki. These are:

  • Class names should begin with a captial. They are "Upper Camel Case" or "Pascal Case"
  • Variable names and function parameters begin lower case. (Lower Camel Case).

These are very similar to the Microsoft Naming Guidelines.

* the only difference in captialisation that I can think of at the moment is that the type "string" in c# is capitalized as "String" in javascript. There's a good page on the Wiki describing more of the specifics of using Javascript in Unity (compared with 'normal' Javascript) here: Head First into Unity with Javascript.

All languages in Unity (JavaScript, C#, Boo) are case sensitive. So, that's about the only rule of capitalization: use exact case.

ok, so there aren’t really firm rules as long as the coder is careful. sorry if this is a basic question, but what are some best practices for when to capitalize?

also, why does this happen when I create a new public variable:
in my js code I write: “public var hue:int;” but the inspector reveals that as capitalized “Hue”
why does the inspector capitalize it ?

I don't think there really are strict rules regarding capitalization; having class-names PascalCase is just a convention. However, all languages used by Unity are case-sensitive - so if you have a class SettingsManager, and you try to refer to that class as settingsManager, that will naturally fail (of course, you could have a variable settingsManager in camelCase).

In general, you need to make sure to use the same capitalization as in the Scripting-Reference whenever you use classes from the Unity API.