Im building game with World Space Camera where i draw 100x100 grid = 10,000 celss where each element is a toggle button. Now most of the time user will b in zoom in stage which means only few 100 cells will b visible to camera.
Something like rectmask2d pops in my mind, but you would need to get the rect mask to match the position of the camera at any given time.
But to be honest, I would recommend not using an ui for that task. Batching is not the best there, it all runs on the transparency queue, so you can’t do any ztesting and recalculating the ui if anything moves sounds like a nightmare for the cpu. Could you do it with normal GameObjects /Meshes/Sprites and raycasting? I think that would be the way to go. Otherwise, maybe show a bit of how you thought the ui looks like and what your plans are.
Thank you for your reply johan,
Im actually trying to make a color by number grid https://i.pinimg.com/564x/fc/6c/40/fc6c40923ab1abe31d609acbc8ebf684.jpg
i want to use uGUI as it feels easier
however in your opinion if i simply draw that grid with cubes with TMPRo text on it, 'd it be better performance wise than typical UI due to culling?
Ah okay I see! Hm, just to get on the same page: You got a camera that handles the zoom and movement and a worldspace UI so it does not need to be recalculated when the view moves?
If that is the case, it should not be too hard to change it to blocks as I was suggesting. I did a quick test and batching of textmeshpro elements that are not in the ui was really well:
(You can see that the rendering of all textmesh pro elements takes up just one draw call. For UI, if you don’t work very precise this can end up with one drawcall per text! (Btw. you can profile the number of draw calls via Window->Frame Debugger).
So that’s the way to go I would say. I think performance might be even good when should all cells at once, if you’re smart with materials and batching.
If however you implemented the ui to be a screenspace overlay or screenspace camera and the movement happens in the ui, a quick fix would be to just add one root panel to the canvas that is the parent of all other elements that fills the whole screen and has a rect2D component attached. I fear that performance will be very bad when showing all cells at once. So consider switching
Sorry for reviving this post. Having a long list of about 1k items to display in some place, I am currently using word space canvas and culling with a rect mask 2d. However, culling with rect mask, resulting performance (~90ms) is even worse then just render-it-all (~50ms)… I think I shall use something else to cull it.
I am considering pre-culling myself. Maybe that is the only way for it.
Actually I have implemented a simple culler (if none of GetWorldCorners in sight discard the rectangle) myself, consuming ~4ms for 1000 objects. I found that if I call RectTransform.rect for a sounder culling (since edge may still be partially visible when vertices are outside screen rect) it becomes just as laggy as the RectMask2D solution. Maybe RectTransform.rect is doing some expensive calculation like propagating the transform matrix down the hierarchy or so.