Search Unity

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

Discussion in 'Editor & General Support' started by TiggyFairy, Mar 10, 2023.

  1. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    506
    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?
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,910
    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.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,726
    SCRIPTS OR ASSETS ARE MISSING OR BLANK

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

    https://forum.unity.com/threads/problem-with-git-and-missing-scripts.1090876/#post-7024801
    https://forum.unity.com/threads/scr...ead-after-loading-editor.998413/#post-6487297
    https://forum.unity.com/threads/scr...ead-after-loading-editor.998413/#post-6488230

    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.
     
  4. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    506
    Wow. That's.... a lot more complicated than I ever thought it would be, but thanks.
     
    Kurt-Dekker likes this.