Search Unity

Feature Request You shouldn't be able to put spaces in script names!

Discussion in 'Scripting' started by Sooly890, May 16, 2023.

  1. Sooly890

    Sooly890

    Joined:
    Aug 24, 2022
    Posts:
    107
    That could be very confusing to some beginners. Specifically because of the error: No Monobehavior scripts in file, or their names do not match the file name
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,925
    Scripts are just text assets (specifically, MonoScript assets), and technically speaking they can be named whatever. It's only in the case of scriptable objects and monobehaviours that there's a special requirement that the script's asset name and the actual C# class name need to match exactly.

    In other cases the script's asset name can be whatever it wants, just that 99% of the time folks ensure the script and class name match out of good practice.

    And by the way, class names can't have spaces. So putting a space in when making a new script would just cause a compiler error, unless Unity omits the spaces from the class name.
     
    Last edited: May 16, 2023
    orionsyndrome and Bunny83 like this.
  3. Sooly890

    Sooly890

    Joined:
    Aug 24, 2022
    Posts:
    107
    ah, I see. Thanks for correcting me!
     
    spiney199 likes this.