I implemented a custom ViewPager, basically to scroll through different UI panels.
It works great but, it has absolutely horrific performance on mobile devices.
I use the three interfaces
IBeginDragHandler
IDragHandler
IEndDragHandler
The main calculation happens in IDragHandler, but it’s not as much calculation as you would expect it to get jiggerish. I only do some positioning stuff in there.
That’s why I was wondering how often the IDragHandler-method gets called, every time the pointer is moved, once every Update?
I hope you have some suggestions to that.
Thanks in advance!
its likely not the drag handler calls but the implementation you’ve put in the drag handler, or how you’ve set up the UI in the scene.
can you show the code you’re using in the drag call (preferbly the entire class). even simple postitioning can cause frame loss if not done properly.
is any of the objects in the Canvas Heirarchy not coplanar?
is the render mode on the canvas set to “screen space - camera”?
Do you have one monolithic canvas with a lot of child UI elements or several smaller, nested canvases?
does the canvas have a ton of child UI that move, change color, or change text?
all of these can force the UI system to clear the render buffer and start completely from scratch on the new frame. especially multiple moving UI elements on one canvas.
if the UI is not coplanar then that means the UI has depth, thus it has a perspective. At which point the UI system can’t assume that the perspective won’t change so it redraws that canvas
Ui rendering is mostly handled on a separate thread, but Camera Mode can throttle that as now the UI has to wait on the camera. world space isn’t much better (even if the ui hasn’t changed, new perspectives require a redraw, so the UI just assumes it always has to redraw in that mode)
splitting the UI into one canvas full of the static UI and multiple other canvases with dynamic UI can greatly improve the performance on the system as a whole (as now the UI will only redraw the tiny canvases that changed instead of redrawing everything).
finally when a Ui element changes, that element and everything drawn behind it (in that canvas) will need to be redrawn. which is why elements that constantly change appearance are best on their own canvases
So as you can see you can probably understand why simple positioning in code can cause your performance issues.
Great. And about the Render mode, “Screenspace - Overlay” is the fastest one I was just asking if you were using screenspace camera as that can slow it down.
and yes with how you have your UI set up this code can cause a performance hit