unity io_error ai_generated true

AssetDatabase.Refresh failed: Could not refresh asset 'Assets/Resources/data.asset' because the file is locked by another process.

ID: unity/assetdatabase-refresh-failed-locked-file

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2023-02-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Unity 2020.3.0f1 active
Unity 2021.3.0f1 active
Unity 2022.3.0f1 active
Unity 2023.2.0f1 active

Root Cause

A file in the project's Assets folder is locked by an external program (e.g., version control, text editor, or antivirus), preventing Unity from reading or writing it during refresh.

generic

中文

项目 Assets 文件夹中的文件被外部程序(例如版本控制、文本编辑器或防病毒软件)锁定,阻止 Unity 在刷新期间读取或写入它。

Official Documentation

https://docs.unity3d.com/ScriptReference/AssetDatabase.Refresh.html

Workarounds

  1. 85% success Identify and close the locking process: Use tools like Sysinternals Handle.exe to find which process has a lock on the file. In Command Prompt: handle.exe -a "Assets/Resources/data.asset" then close the identified application (e.g., Notepad++ or Git).
    Identify and close the locking process: Use tools like Sysinternals Handle.exe to find which process has a lock on the file. In Command Prompt: handle.exe -a "Assets/Resources/data.asset" then close the identified application (e.g., Notepad++ or Git).
  2. 80% success Exclude the Unity project folder from antivirus real-time scanning to prevent locks. Then restart Unity and perform a refresh.
    Exclude the Unity project folder from antivirus real-time scanning to prevent locks. Then restart Unity and perform a refresh.

中文步骤

  1. Identify and close the locking process: Use tools like Sysinternals Handle.exe to find which process has a lock on the file. In Command Prompt: handle.exe -a "Assets/Resources/data.asset" then close the identified application (e.g., Notepad++ or Git).
  2. Exclude the Unity project folder from antivirus real-time scanning to prevent locks. Then restart Unity and perform a refresh.

Dead Ends

Common approaches that don't work:

  1. Run Unity as administrator 80% fail

    Administrator privileges do not unlock files held by other processes; the lock persists.

  2. Delete the locked file and recreate it 70% fail

    Deleting may succeed but the new file can be locked again if the external process is still running.