Detecting enclosed rooms?

I’m making a building system with a feature where the player can only place certain types of blocks in an enclosed room which they have to build first. To detect said enclosed rooms, I would use flood fill to check each tile. So far I have 4 options:

  1. To use Region3s or OverlapParams (or something similar)
    This would involve creating thousands of Region3s since even a small 10x10x10 plot would still amount to 1000 tiles.

  2. To store the occupied tiles in a table
    This is similar to the first option since it involves possibly creating thousands of tables for each block placed. For example, A 4x4x4 block would amount to 64 tables (1 table for each tile). If a player is dedicated enough to fill a 20x20x20 plot with 4x4x4 blocks, it would amount to 8000 tables. (if my math is correct).

  3. To use some sort of external API to do the calculating + storing
    I am not exactly familiar with APIs. I don’t even know if this is possible or efficient.

  4. To not do it at all. (not preferred)

I haven’t seen any game do this before (at least in roblox) and probably for good reasons. Is this too ambitious?

  • Option 1: Region3s
  • Option 2: Tables
  • Option 3: External APIs
  • Option 4: no.

0 voters

None of these. You should be using raycasting to detect the bounds of the rooms. Or, if you can, store the extents of the rooms in a variable.

I don’t recommend Region3 because they are deprecated when used with BaseParts.

If I were you, I would use either raycasting or pathfinding. If the path status is NoPath, then that means there most likely isn’t a way out of the room. If it’s success, then there is. Just use the correct AgentParams.