- Home /
How to rename a script file?
How I can change the Name of a Javascript file? ("NewBehavoiurScript")?
I cant find any rename button (enter or F2 also doesnt work).
Im using a mac. Thanks
Answer by Lipis · Mar 15, 2010 at 10:47 AM
Select the JavaScript file or any other object in Unity and press:
return key
if you are on MacOSF2
if you are on Windows.
You're welcome... If you haven't read that already you should take a look if you are new around here or stackoverflow.com: http://answers.unity3d.com/faq regards
That is a lifesaver. Also works on material assets etc. This is so counterintuitive that it should be fixed in Unity.
Can't we change the button function from F2 to Enter in windows only for unity.
Answer by Eric5h5 · Mar 15, 2010 at 02:16 PM
Aside from the return key, you can click on a file, wait for a bit, then click again (don't click again too fast). This is also the same way to rename files in the OS.
This works, but then the game object starts complaining that it can't find the file. Strangely it does use the new renamed name, but still can't find it.
Answer by davemeta · Dec 18, 2012 at 09:32 PM
The only way to fully and gracefully rename a monobehaviour script that I have found:
Inside of Unity, rename the file that contains the script to the desired name. (Select the script, wait 2 seconds, click again, then type the new name)
Inside of MonoDevelop, open the script, right click on the class name, choose "refactor" > "rename". Uncheck the "rename file" box.
Make the new class name the same as the new file name you used in Unity.
Save all open MonoDevelop files.
Close Unity (don't save the scene)
Open Unity
Now your monobehaviour class is fully renamed / refactored.
That's a nightmare! It's faster to create a whole new script and paste all code in there :-(
Not always. If your script is used on multiple objects, they would still use the old script. With the method above, the components on your objects and préfabs will automatically be updated to use the newly named script ins$$anonymous$$d.
This is very helpful. I had a prefab that the script was attached to. This saved time.
Works perfect! Even with Visual Studio. Thanks - That should be the accepted answer
It doesn't work for me in the combo:
Unity 5 Windows Raider
Answer by renderhjs · Jun 17, 2010 at 03:54 AM
Hitting F2 in Windows with folders doesn't work sometimes - it just goes back to the former folder (just like a Assets folder keep re- appearing within the Assets folder after deleting it). Clicking twice on the folder name and then giving it a new name works however, so it seems to be broken on windows at times.
I've found it's the other way round, double clicking no matter what speed you do doesn't work sometimes. F2 seems to work fine for me and remains working fine even when double clicking doesn't work.
Answer by Ben Wilkinson · Dec 15, 2010 at 11:27 AM
I have also found that if you create a new folder in project view (called "new folder" by default) then edit the name, then press enter, it just pops back to "new folder". Its very frustrating. I think this could be a bug. Im using windows vista and unity 3 pro and ran it a admin but still no luck.
I know it's old but if you are still having the problem then it's because you are not hitting Enter/Return after you have finished editing the name
Your answer
![](https://koobas.hobune.stream/wayback/20220612111523im_/https://answers.unity.com/themes/thub/images/avi.jpg)