Computing occlusion culling at runtime! What do I miss?

I spent a week to write a custom occlusion culling script for my project. I build a dungeon city by procedural generation at runtime that holds up to 100’000 cells per level each with multiple tile objects, so around 500k objects for one level (levels will stack) of the dungeon (just the static structures, no furniture or any other objects):


[rooms + long hallways in different colours, doors in yellow]

Of course, without occlusion culling I had like 7.6Mio verts rendered per frame. I wrote a chunk based frustum culling script that worked fine, but no chance for occlusion culling. I searched the internet for hours for a solution, till I found this line of code: UnityEditor.StaticOcclusionCulling.Compute();

I run that after the generation of the dungeon and voilà: perfectly working occlusion culling!
But the question for “dynamic” (in runtime, no pre-baking) occlusion culling is in the internet for years now and no post about that solution!? Is there something I miss? Where is the catch in it?

I think what you missed is the namespace that this method comes from:

UnityEditor is a namespace for API that only exists inside the Unity editor, so you can’t run it at runtime.

The software that computes occlusion culling is likely part of the editor itself an is not included in your build.

I see. Now I understand better. What a cr@p…
Well, if I finalize the project, maybe I invest into an Asset that will provide this feature.
Are there other solutions than buying an 3th party Assets (I wanted to do my project all alone without Assets, it’s not about money)?

Unity does not have any other occlusion culling, so you’d either need a third-party asset or code it yourself.

Unity 6’s keynote showcased a GPU-based occlusion culling system but I don’t see a thread for it.

Oh, that cool! It’ll probably be in beta for three years or something, though. :stuck_out_tongue:

Related:

Custom Occlusion Culling in Unity

^^^ Shouldn’t be too hard to replicate.

With such a dense city you may be able to get away with just reducing the draw distance. And when indoors you can reduce it even further. Also, rather than set the draw distance to discreet values you can lerp it between the required values so it’s not as noticeable. And add some linear fog.

Are you interior or exterior? How much view there is between room? Because if there us very little view interactions, you can probably do a very naive culling by simply render the current room and x connected room from it. Given you don’t seem to have a lot of long sight view. The chaos of turn should take care of it in one or two rooms.

Thanks for all the replies.
Well, I also reduced the render distance, but with the long hallways it would break some immersion. The idea was created from a dream I had about a huge and high reaching round city in the desert.
Its easy to add pillars or banners during creation iteration to add a feeling of a vast structure, so there should not just be gloomy and creepy dungeon rooms, but also high, long and bright hallways connecting the single apartments and rooms (the single levels of the city should stack like seen by the tower of babel). I recreated the dream-scene with photoshop:

I also made an attempt where every visible room transition (door, etc) enables the room behind it, but the cascade adds more problems than it solves, especially when it comes to hallways and rooms connected in circles (although in the code its easy to make a check, in runtime it wont work properly).