I’ve been working on a 2d sandbox game for awhile now and after trying just about everything I could I still haven’t found a good way to manage the meshes of the world in a manner that doesn’t either hurt FPS or cause massive GC ticks. I’ll quickly go over what I have tried, what I think would help in the hopes that someone might have a suggestion to help me out!
So in our world we have tiles that make up the world, these tiles are editable by the player, there is a pretty good amount of them (about 3000 of them).
So far I have tried:
Creating a mesh that I update with changes and reassign the verts (The problem with this was massive GC ticks due to the fact you cant SET the length of verts used by a mesh, you must clear the now unused verts from the stack, which basically just means copying the array, which is horrible).
Same as above, but instead of reassigning the verts, setting all the unused verts to vector3.zero (this cost far far to much in the loop and basically grounded the FPS)
Using GL calls to directly render the scene (This works ‘okay’ but it results in far far more processing power due to having the loop inside of c# instead of allowing unitys rendery to handle it).
Creating one quad (a mesh that just has one quad) and redrawing it to the screen wherever I need it, with pre-calculated colors and UVs (This worked the best over all but its still very performance heavy and not really a real solution).
What would be great to have:
A version of Graphics.DrawMeshNow that takes parameters like so, Graphics.DrawMeshNow(verts, uvs, colors, length) where the length is the amount of the arrays I wish it to actually use so the values in the arrays I wish to use, so I never need to thrown away the array I can just pre-calculate the max amount ever needed and stick with it.
Any suggestions would be great!