Hi everyone,
I’m building a Fallout Shelter / SimTower–style side-view base management game in UE5 (2D gameplay on an XZ grid, rooms placed in cells, orthographic camera).
Right now I’m trying to hard-limit the camera to the exact playable area of my grid (so the camera can never show anything outside the grid bounds). The grid itself is data-driven (a struct array / generated cells), not individual actors per cell.
What I tried
I attempted to clamp the camera using calculated world bounds derived from my grid settings:
-
Grid origin (world)
-
Cell size
-
Grid width/height in cells
-
Optional “forbidden columns” on the left/right (spawn lanes that must never be visible)
Then every tick I:
-
read viewport aspect ratio
-
compute orthographic view half-extents from
OrthoWidthand aspect -
clamp camera center so camera edges stay inside the computed world rectangle
-
also clamp zoom so zoom-out can’t reveal outside the rectangle
What’s going wrong
Even though the math seems correct, the results are consistently wrong in-game:
-
when panning upward, the camera stops early and can’t reach ~9 top rows
-
horizontally it still leaks ~2 cells outside left and right
-
downward it leaks ~3 cells outside
-
the “margin” changes depending on zoom: when zoomed out the offsets become much larger, which makes the clamp feel broken
So it looks like my “grid bounds” calculation is not matching what the camera sees as world space.
Why I think it happens
Because the grid is mostly struct data, there is no actual per-cell scene component/actor transform to query. I’m generating world positions mathematically from config values, but the camera seems to be constrained by something else (level placement/transform/offset/rotation/scale, camera component offsets, or something in the actor hierarchy).
I suspect the mismatch is caused by some transform offset (GridActor moved/rotated/scaled in the level, background plane rotation/offset, camera pawn being a BP child with hidden component offsets, etc.). That would explain why the “correct” numbers don’t match what’s visible.
Question
What’s the recommended UE5 approach to clamp an orthographic camera to a grid area when the grid is data-driven, so the camera bounds are based on the actual world placement (what you see in the level), not just config numbers?
I’m open to any approach:
-
computing bounds from the GridActor’s transform/components (e.g., component bounds)
-
using a dedicated “bounds component/volume” driven by the grid
-
or even best practices for this kind of camera constraint in a grid-based side-view builder
I’m doing everything in C++. Any ideas or patterns that work reliably would be hugely appreciated.
Thanks!