C# script becomes - backup when script gets created.

Hello!

When I create a new script it creates a .cs - backup file instead of a .cs file how do I fix this problem.
I am quite new to Unity programming so I don’t know if I did something wrong.

Kay

I found a fix for this issue!

Just look in “C:\Program Files[your version of Unity]\Editor\Data\Resources\ScriptTemplates” (or the corresponding directory on Mac/Linux). See if there are any duplicate files in there, specifically one called “81-C# Script-NewBehaviourScript.cs - backup.txt”. If so, move it somewhere safe and then close Unity. Make sure there is also a file called “81-C# Script-NewBehaviorScript.cs.txt” in that ScriptTemplates folder and leave it there.
Open Unity again and everything should work.


Previously, I had changed the file “C:\Program Files\2019.3.5f1\Editor\Data\Resources\ScriptTemplates\81-C# Script-NewBehaviorScript.cs.txt”, so I could add my own default script template. However, I left the original one in that same folder as “81-C# Script-NewBehaviourScript.cs - backup.txt”.
Unity must have gotten confused between the two files. This didn’t create issues at first, but I started installing assets (specifically, Bolt) and maybe that made Unity recompile things and recalculate which default file it’s looking for.


I moved my backup file somewhere else, then right-clicked in Project view > Create > New C# Script. Unity gave me an error saying it was looking for 81-C# Script-NewBehaviourScript.cs - backup.txt. Aha!
So I restarted Unity, tried adding a new script again, and it worked, using my custom template.
If this doesn’t work for you, try adding a new script using the Inspector’s “Add Component” menu. And if THAT doesn’t work, you may just want to update your Unity version to fix this rather than manually renaming new scripts in File Explorer / Finder / Nautilus every single time.


More info: https://support.unity3d.com/hc/en-us/articles/210223733-How-to-customize-Unity-script-templates