Hello everyone,
I have created a custom Scripted Importer which parses a .csv file and generates a ScriptableObject main asset & a mesh sub-asset, along with a ScriptedImporterEditor which handles the UI.
I have noticed that when the .csv files tend to be large (200.000+ lines / 20+MB), any UI operation while the .asset is selected lags considerably. Selecting the .asset in the first place on the Project window, changing some settings on the Inspector, pretty much any mouse operation regarding that object, makes UnityEditor horribly slow.
Keep in mind, the OnAssetImport() function call itself is fast, and even removing all the functionality from it doesn’t solve the issue. The issue persists even if I disable my Editor script.
Even if I completely remove my Importer, the text asset selection is still slow, which leads me to believe that Unity does some pre-serialization any time the .asset is selected.
Aah yes, of course. I attach the results below. UnityEditor::ActiveEditorTracker.VerifyModifiedMonoBehaviours
called from UnityEditor::InspectorWindow.OnInspectorUpdate takes up 712ms (94%)!
I also noticed that there’s a big GC spike whenever I select the asset.
I have the same issue with Dialogue Database of “Dialogue System for Unity” asset.
Basically one 20mb serialized asset. Whenever this asset is selected in Project view Unity becomes extremely laggy. Profiler shows similar picture.
I just had a similar problem happen and found out what caused it for me. (same profiler results)
I had a custom Editor to draw in the inspector. The monobehavior itself had simple several serializable objects (not even unity objects) to hold data. Those objects had references to their parent object (with the monobehavior at the top).
Because I would copy lists of serializable object between monobehaviors I would have to update the parent references accordingly. I would just do an assignment of the parent object in the OnInspectorGUI().
From what I can tell, this has caused the slow down, as unity possibly marked that down as the serializable object being changed causing the whole serialization to check and verify for changes.
Adding a check first to see if the parent object is actually different fixed the slow down.
TLDR: Be careful with assigning serialized objects every update in the editor loops.
Hello, I’m not sure what you mean by “Adding a check first to see if the parent object is actually different fixed the slow down.” Could you please let me take a look at this part of the code? Thanks!
If the asset has a custom editor, you could mark chunks of that editor with Profiler.BeginSample and Profiler.EndSample, to see which part is being slow.
I tried to reimplement the custom inspector so it did returned right at the beginning of OnGUI and it’s not helped a bit. The issue is on the engine side