VisualElements in ScrollView dirtied when?

I have some custom VisualElements in a Scrollview which use OnGenerateVisualContent to generate a mesh. Generally working well, however when I scroll only some of my elements receive a call to OnGenerateVisualContent() - some that are visible in the scroll area are not called. Are there any rules about when an element is marked dirty related to scroll views?
I guess I can call MarkDirtyRepaint on all elements when scrolling - my assumption is if an element is dirtied multiple times in the same frame (i.e. via my call + sometimes automatic call) that OnGenerateVisualContent will still be called just once per element in that frame?

Many thanks.

The ContentContainer inside the Scrollview has UsageHints.GroupTransform set. This allows the renderer to move the vertices on GPU so that we avoid the performance cost that comes with frequent geometry generation (generation + upload + implied fragmentation). In some cases also (e.g. without UsageHint), when only the position changes (styles and size remain the same), it’s possible that we don’t call OnGenerateVisualContent and just offset the vertices on CPU.

I would recommend that you call MarkDirtyRepaint on elements that need to have their custom geometry updated.

Yes

Out of curiosity, what is your use case, why do you need to regenerate the geometry?

1 Like