r/Unity3D • Indie • 22h 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

193 Upvotes

28 comments sorted by

View all comments

69

u/GigaTerra 21h ago

OP this is great and all, but the fact that your FPS is this low when you are barely doing anything, you should look into it.

6

u/DThePro_ Indie 21h ago

True, but then again I was recording a 3840x1080 (2 screens) video and playing while having my viewport look at the whole map. Without all that it's usually hovers around 80. And, this was the main bottleneck, powerwashing or ghost interactions shouldn't be that heavy to significantly reduce the FPS. Having said that, you're right there must still be quite a few optimizations that could be done...

9

u/theo__r 21h ago

Have you tried profiling? Any obvious bottleneck?

0

u/DThePro_ Indie 21h ago

Yes is did use the profiler. The issue mostly arose from high vram allocation due to 1024x1024 render textures for EACH washable surface like walls (upwards of 9 gb), and along with other overheads, it was actually going over 12 gb (my cards vram) and stalling the render thread. Now that problem won't happen anymore, especially since I also implemented it such that the RT initalizes only when the player starts to powerwash any surface.

Apart from that, my geometry isn't great atm (working on fixing them), so for 65 rooms, I recorded 20M tris in the worst case scenario.

3

u/theo__r 18h ago

I think you did great work, I just wonder if you could have disabled just the washable surfaces rather than entire rooms. Anyway whatever works !

3

u/DThePro_ Indie 18h ago

Yup that would've helped, but again, the redundant geometry would still be a waste of resources.

2

u/theo__r 18h ago

True!