Renaming files using Ctrl + r in Visual Studio breaks Scriptable Objects

Basically, if you rename a Scriptable Object in Visual Studio 2022 Unity does not recognise the change and says the script is missing. You can fix this by dragging the renamed script into the object's script field. HOWEVER this resets all the fields. So, yeah, I'm doing a lot of stuff for the third time :P

Any way to let Unity know about this?

You generally should not be renaming or altering files from under Unity (aside from editing script files).

Change the script name in Unity, same with any other asset.


Some info about Missing script warnings, broken prefabs, GUIDs, renaming GUIDs, etc:

EVERYTHING in Unity is connected to the above GUID, which is stored ONLY in the metafile, and hence why the metafiles ALWAYS MUST be source-controlled.

When Renaming: It is super-easy to inadvertently change the GUID by renaming outside of Unity. Don't do that. Instead:

  • close Visual Studio (important!)
  • rename the file(s) in Unity
  • in Unity do Assets -> Open C# Project to reopen Visual Studio
  • now rename the actual classes, and MAKE SURE THE FILE NAMES DO NOT CHANGE!

If you are NOT using source control while you do this, renaming files is an EXTREMELY dangerous process.

Use source control at all times so that you can trivially revert if you miss a critical step and damage your project.

Wow. That’s… a lot more complicated than I ever thought it would be, but thanks.

1 Like