Using variable names as seen in the inspector

A variable by the name of fireResistance becomes Fire Resistance in the inspector.

Is there any way to display the name like that (Fire Resistance) in a text? (without converting it manually)

I could name it Fire_Resistance and then just replace “_” with " ", but I wan’t to know if there is a more direct way first.

If you are creating an Editor script, then you can use ObjectNames.NicifyVariableName defined in the UnityEditor namespace (hence, you can’t use it in a build)

Otherwise, implementing such function is not complicated

public static string NicifyVariable(string input)
{
    System.Text.StringBuilder output = new System.Text.StringBuilder();
    char[] inputArray = input.ToCharArray();
    int startIndex = 0;
    
    if(inputArray.Length > 1 && inputArray[0] == 'm' && input[1] == '_')
        startIndex += 2;
    
    if(inputArray.Length > 1 && inputArray[0] == 'k' && inputArray[1] >= 'A' && inputArray[1] <= 'Z')
        startIndex += 1;
    
    if(inputArray.Length > 0 && inputArray[0] >= 'a' && inputArray[0] <= 'z')
        inputArray[0] -= (char)('a' - 'A');
    
    for(int i = startIndex ; i < inputArray.Length ; ++i)
    {
        if(inputArray *== '_')*

{
output.Append(’ ');
continue;
}
if(inputArray >= ‘A’ && inputArray <= ‘Z’)
{
output.Append(’ ');
}
output.Append(inputArray*);*
}

return output.ToString().TrimStart(’ ');
}
Debug.Log(NicifyVariable(nameof(MyVariable))); // My Variable
Debug.Log(NicifyVariable(nameof(m_TheOtherVariable))); // The Other Variable
Debug.Log(NicifyVariable(nameof(__AnotherVariable))); // Another Variable
Debug.Log(NicifyVariable(nameof(kSomeConstant))); // Some Constant
Debug.Log(NicifyVariable(nameof(someVariable))); // Some Variable