If in my script will be compilation error. Editor will be crashed.
yes, if there is any infinite loop both unity and unreal editors may crash
The issue originated from my Editor script, available here: CodeGenerator. The script was active and triggered the OnEnable method as soon as I launched the editor. While the exact cause of the crash remains unclear, I opted not to investigate further and instead implemented a 10-second delay for the initialization process. The delayed logic includes:
- Loading multiple values from
PlayerPrefs. - Gathering all
.csfiles from theAssetsandPackagesdirectories (excluding files in ignored folders) with this code:
csharp
Copy code
string[] csFiles = Directory.GetFiles("Assets", "*.cs", SearchOption.AllDirectories)
.Concat(Directory.GetFiles("Packages", "*.cs", SearchOption.AllDirectories))
.Where(filePath => !_ignoredFolders.Any(ignoredFolder => filePath.Contains(ignoredFolder)))
.ToArray();
Debug.Log($"{PLUGIN_NAME}Found {csFiles.Length} .cs files.");
foreach (string filePath in csFiles)
{
string className = Path.GetFileNameWithoutExtension(filePath);
classToPath[className] = filePath;
}
- Checking
.gitignoreandignore.conffiles in read-only mode. - Initializing a reorderable list for bookmarks with the following setup:
csharp
Copy code
bookmarkList = new ReorderableList(bookmarks, typeof(Bookmark), true, true, false, false);
bookmarkList.drawHeaderCallback = (Rect rect) => EditorGUI.LabelField(rect, "Bookmarks");
bookmarkList.drawElementCallback = DrawBookmarkElement;
bookmarkList.onReorderCallback = (ReorderableList list) => SaveBookmarksToPrefs();
This approach mitigates the crash by delaying the execution of potentially resource-intensive processes.
Why is an editor tool writing to player prefs???
I cannot fathom any reason why it would need to do so. At the very least it should be editor prefs, but you can easily write data to a ScriptableSingleton to persist data between domain reloads.
Thank you very much. Changing PlaerPrefs to EditorPrefs solved the issue
I would still suggest using a ScriptableSingleton alongside the [FilePath] attribute to write this data to disk when required: Unity - Scripting API: ScriptableSingleton<T0>