I recently upgraded from 2021 LTS to 2022.2.1.f1. I have made my own implementation of a ReorderableArray since long ago that utilizes the UI Toolkit. It was working fine until the upgrade. For some reason, I’m noticing huge lag when drawing an inspector. Can’t really pinpoint anything, since this didn’t exist before. I’m leaving a screenshot of the profiler. It feels like the inspector is being rebuilt every frame?
EDIT2: Calling new InspectorElement(obj) when I want to draw that object in another Inspector seems to be the issue. I have a number of SO inspectors I want to draw inside that inspector in a list. Creating an InspectorElement on the “child” SO makes the Inspector be redrawn every frame. The “child” SO is a child asset of the SO whose inspector is being drawn. I don’t know if that has anything to do with the bug though.
I think it’s understandable that it isn’t very fast, as it shouldn’t create a new Inspector every frame. My guess is something is making it be recreated every frame, but without looking at your code it’s very hard to know what it is.
There is no useful code to look at. The line that’s causing this is new InspectorElement(obj), where obj is a SO that’s different than the inspected object. If I remove that line, everything is fine. And the code worked perfectly fine for older versions of Unity.
That doesn’t mean there’s nothing to look at. For example, if something somewhere is calling Bind, it could cause the InspectorElements to reset their contents.
EDIT
I see how the fact that it worked before could mean that there’s nothing else in your code that could be causing this, but the thing is a lot of internal changes that are technically correct could’ve caused your issue. With UITK, it’s not hard to rely in implementation details without noticing. It’s happened to me.
I’m not saying that this is what is happening to you. All I see for sure in your image is that an InspectorElement is being rebound every frame. I don’t know why. If you share some code, I might be able to tell. Or at least I could give you some ideas.
EDIT2
Plus, even if it’s a Unity bug, it’s easier for Unity devs to replicate the issue if you add some basic code to replicate your problem in your bug report.
It’s not happening to me, though, that’s also why I’m not sure it is a bug. I also have a custom reorderable list of inspectors. I don’t inherit from BaseVerticalCollectionView, though.
Unfortunately, I can’t pinpoint the cause of the lag. I copied only the necessary files to another project and the inspector is created only once. It must be some left-over asset or some old code that affects all the inspectors. I may look at this on another 2022 release that’s more stable. Aside from this the Editor constantly crashes when tampering with particles and the shortcuts aren’t working.
I’m switching back to 2021. I hope newer versions fix these issues because I was planning on having 2022 as the final Unity version for the project.