I am currently working on a 2d Isometric City Builder Game and for this, I have a script that procedurally generates a map with 2d sprites. In general, these sprite are placed as own gameObjects which leads to the fact that I always have around 19-20k gameObjects. For rendering, this is absolute pain and costs a lot of performance and causes low fps and high draw calls, even if the camera viewport size is low.
These instantiated gameObjects have PolygonColliders2D on them as well as a Sprite Renderer but no script.
Does anyone know some tips or tricks in which I can increase my performance up to around 30-40 fps if the camera viewport covers all gameObjects? I tried GPU Instancing with a new material for each sprite but i had no real effect. I have no other idea how I can solve this performance issue…
The advice additional to the good advice above is to also learn how to use the profiler too because it’s your friend when you need to know what’s causing performance issues and when.
These are convenient but they are unlimited in how many convex polygon shapes they’ll produce each too. You can see shape-count in the “Inspector > Collider2D > Shape Count”.
All that said, what you’ve created (as discussed above) is just a brute force set-up with too many instances of separate components doing their own thing.
Thanks for the answers. Concerning the tilemaps feature its not possible to create larger worlds with procedural generated maps and tiles with this, that is why I am using the gameObjects aspect which, I know, is not performant and causes low fps. I used the profiler which showed what I already knew…that the rendering took 90% of my CPU usage which caused the inperformant appearance. That is why I looked for an answer which would offer other alternatives.
I solved the problem myself by creating a Sprite Atlas with help of this tutorial. With this, I am up to 40 fps when using a wide Camera viewport and up to 60-65 fps when zooming in. For a mobile game it is enough, even if the frameRate of the target device is often limited to 30 fps.
yeah, there is huge performance benefit from reducing polygon collider shapes and geometry.
Any plans for some builtin tool or option to optimize those shapes? (although not sure where it should be, not fun to manually click through all colliders, but also cannot be global if some colliders should be higher quality)
@fabianschmidt2512 if you want to test my polygon collider optimizer,
here’s asset store coupon: ASV-NJMN-3DA4-E49A-9NLW-UUUG (lets hope nobody else takes it… or pm me if its gone : )
We added Delaunay tessellation in 2022.1 as an option for PolygonCollider2D, CompositeCollider2D and TilemapCollider2D. This typically produces far fewer shapes when curves are involved (those triangle fans are reduced). We’re also looking at work for editing physics shapes for sprites too which means there’s no longer just outlines but instead physics primitives available baked in the editor which also means no runtime tessellation involved and the PolygonCollider2D doesn’t need to perform any work or store the outline (only if you edit it directly).