Unity Procedural Game Optimization

I am currently developing a 3d dungeon crawler which implements a procedural dungeon generation system which works perfectly fine. However the game is not very performant. I have tried a few optimization tricks I heard like:


  • Adding LOD Groups to each room prefab (this works perfectly fine), has impact on fps and batches
  • Tried addig static batching, I made every room prefab static and enabled dynamic and static batching in the player settings, however there is no change in the batches count or the saved batches count.
  • Tried addind occlusion culling but i cannot bake it before the game, as it’s a procedural generated world.
  • The room prefabs are low poly rooms and are not even decorated yet, just the floor and walls and torches.

I should mention that i am using deffered lightning and I am activating the torch point lights as the players walks in the room. There aren’t any baked lights everything is realtime. Every room prefab uses the same metrial and is not copied when the room is instantiated.


Some screenshots to help you understand better:
[1]: https://i.stack.imgur.com/msoBy.png
[2]: https://i.stack.imgur.com/vpuTT.png
[3]: https://i.stack.imgur.com/WF6Y6.jpg
[4]: https://i.stack.imgur.com/S7hQz.jpg

According to Unity - Manual: Using occlusion culling with dynamic GameObjects you can add occlusion culling to static objects during runtime (static means it’s not moving, even if they’re “dynamically generated”)

“A dynamic GameObject can be an occludee at runtime, but it cannot be an occluder.”

Have you tried setting the prefab to static and seeing if the occulsion system is working at runtime?

Otherwise I’d have a look at Occlusion Areas: Unity - Manual: Occlusion Areas

however there is no change in the batches count or the saved batches count.


If you set a game object to static at runtime, static batching only takes place if you call StaticBatchingUtility.Combine() on your root object. See here. For example, if all your rooms are under a game object called ‘dungeon’, call StaticBatchingUtility.Combine on the ‘dungeon’ game object after all rooms are generated. This will enable static batching and you should see your saved batches count increase, and your performance drastically improve.


Another thing to mention, occlusion culling isn’t really possible at runtime. My guess would be it would be slow and costly to calculate in the first place. However, since your dungeons are small interior rooms with small hallways, you could set up a simple occlusion culling system manually, to turn off all rooms if the door is closed, for example. So any rooms with closed doors are deactivated, and if you are inside a room with a closed door, all rooms are deactivated. This might be a lot harder to implement, since you’ll have to set things up at runtime, but it seems like the best solution to increase your performance.


Hope that helps

That’s what i came across in the first place. I have set all my room prefabs as static but i still need to go to the occlusion inspector tab and bake it. But i haven’t got any meshes in the scene to bake. I will take a look at the occlusion area and come back with a response. Thanks

Ok i found out that the occlusion culling works at runtime if the room prefabs are set to static and it only shows how it work when you click visualize on the occlusion culling window my guess is that this is what is happening when the game is running under the hood.
Thanks @Riiich, if you have any other optimization adivce, I would really appreciate it.