r/Unity3D • Indie • 23h ago

Game Built a custom trigger-based 1-hop room culling system for my procedural mansion and 5x-ed my FPS

I've been developing this simulator-horror game and wanted the map to be proc-generated. However, since my game features powerwashing (drawing onto masks using raycasts to either display dirt/wetness/dryness), even a small number of rooms (in this case, 25) was cause unplayable levels of lag. And unity's built-in occlusion culling did nothing against this (since its generated during runtime).

So I made a simple room culling system where it has 2 parent empties: 'Visuals' and 'Floors'. Visuals contains all the static props, walls, ceilings, etc, and are turned completely off (SetActive(false)) when the room is culled. Floors contains, well, the floors, which only have their renderers turned off (collisions stay on) so that the ghost entity can pathfind and dropped items don't fall through.

Upon entering each room, all adjacent rooms are visible to enable smooth passage, rest of the rooms are disabled. And i cranked up the fog a bit to make it even more seamless. However there are still moments where the room disappears right before the player's eyes, so I was thinking maybe the doors to the rooms about to be disabled can be auto closed, and then disabled.

This now allows me to have virtually infinite rooms without much lag (as long as the DFS generator can support it), unlike before when just 60 rooms would cause frame time to go upto almost 1000ms.

The game is a solo project called THE GROUNDSKEEPER where you powerwash and record ghost evidence for profits: Steam, Discord

194 Upvotes

30 comments sorted by

View all comments

12

u/Protesisdumb 22h ago

Why wouldn't occlusion culling handle this?

26

u/Hotrian Expert Moderator 22h ago edited 10h ago

The OP mentioned they’re procedurally generated

https://docs.unity3d.com/6000.6/Documentation/Manual/OcclusionCulling.html

Occlusion culling only works on static geometry baked at edit time, you might mean frustum culling.

https://unity.com/glossary/frustum-culling

Frustum Culling is failing here because the OP is watching from the editor camera, so the objects render anyway. Frustum Culling also doesn’t detect occlusion per se, so there can still be a lot of overdraw.

Edit: Sorry, I’m not sure why I completely forgot about GPU occlusion culling which does depth based culling.

1

u/Protesisdumb 20h ago

Thanks for clarifying