Poor performance with 1000+ repeated objects?

Hi, I’m making mining/crafting game, where the world generates as you walk through it.
It’s top down, so only 2 layers: Floor and Walls (Ex: No digging down or building up)

However it runs very poorly:

Here is the description of the scene:

  • About 4000 blocks in the world right now, but camera only sees a handful at a time, depending on it’s angle.
  • Every block (except water) is using the exact same material. They are UV’d to a coloured texture lookup.
  • Blocks are about 600 tris cus of rounded edges & uv’d tex lookups. I figured it’s okay because not many are on screen at once.
  • Blocks are dynamic (Dynamic batching is enabled)
  • GPU instancing is turned on

If I try putting lots of grass in the scene, the game drops to an impressive 5fps.

So what am I doing wrong here? I’ve seen videos online of tens of thousands of animating objects moving around smoothly. Should I opt for simpler blocks with actual textures? Did I set up my batching or GPU instancing wrong? Should everything be toggled static on/off when they aren’t moving?

Thanks!
Note: I’ve tried the profiller but have a hard time understanding what to make of it or how to fix it, as I’m not terribly proficient with the unity editor itself.

SRP batching may get you part of the way there, but with this style of game you simply need to go the procedural geometry route. Self plug, I’ve developed a voxel plugin that may interest you: Corgi Voxels - Small+Large Scale Voxels for Built In, URP, and HDRP | Modeling | Unity Asset Store

1 Like

What components are on the blocks aside from the ones responsible for rendering? Are you using a rigidbody and collider for every block?

Chunks of 16x16x16 blocks have a single mesh collider / mesh renderer. No rigidbodies.

For that scene the tris and batches look extreme, probably need revise the meshes and the way the foliage is made

Also adding lot of grass in any scenario without batching or instancing can kill fps, e.g. simple batching will give a change from 80ms to 0.5ms

You might be trying to batch but your stats show 10k batches with basically nothing saved. If all those blocks cast individual shadows (I can’t tell if they all do) that’s going to be homicidal on your rendering performance, plus I think shadows affect batching.

1 Like