How do you get a space to appear in public variables in the editor?

I noticed in a lot of pre-made stuff that public variables appeared with spaces in the editor. For instance, the first person controller’s script MouseLook has a public variable “sensitivityX” but it appears in the editor as “sensitivity X”. I assumed it was because of the capitalization of the letter “X” but when I named a public variable “xAxis” it appeared in the editor as “XAxis”. Just curious on how to make that space appear.

Well, this beautifying is something a lot people complained about. It usually causes more confusion than it does any good. The function responsible is ObjectNames.NicifyVariableName which belongs to the UnityEditor namespace. It’s an external function so we can’t say for sure what exactly it does. However what we know is:

  • It ensures the name starts with a capital letter
  • It inserts spaces at camel-case-points
  • It replaces underscores “_” with spaces
  • It might omit a leading “m_”
  • [… Maybe some more things …]

It seems that in your special case the “first letter capitalization” happens before the camel-case-splitting. So the single “xAxis” becomes XAxis which of course isn’t splitted afterwards.