Unable to rename duplicate scripts

Hi Community,

I’ve recently updated my unity version fro 2021.3.10f to 2022.3.20f1 and i’m having troubles renaming duplicate scripts.

When creating a new script and duplicate it with CTRL+D, enter the duplicated script to rename its class name, it will also result in changing the class name in the primary script that was duplicated.
And it will result in infinite loop of:

Assets\TutorialInfo\Scripts\Readme.cs(4,14): error CS0101: The namespace ‘’ already contains a definition for ‘Readme’

not a big problem when you are creating your own scripts, but more so when an asset came with pre-duplicated scripts naming.

Renaming the script file within Unity will not rename the class name. Duplicating a script may be an exception but I don‘t think it is.

I never duplicate scripts in the editor and very rarely create them in the editor. The IDE is much better suited to creating, duplicating and renaming scripts. Rider for instance will automatically update the filename to match the renamed classname.

2 Likes

I would never duplicate a script either, but in this case an asset came with duplicate script naming.
by saying this :“enter the duplicated script to rename its class name” i meant that i entered the script in the IDE press CTRL+R+R to rename it from the IDE. not from unity editor.

I’ve never used any other IDE than visual studio community and it always have worked for me to change class names prior.

Clearly it’s a Visual Studio issue that you should raise with Microsoft. Rider has no problem with this, yet another reason why Rider is better. Either way, it’s not really the case that, as your title says, you are “Unable to rename duplicate scripts” - you can always replace the type name manually, best with a search-replace with case sensitivity and whole word matching on.

1 Like