0

I'm working on replicating the game "Deepworld". I setup world gen using array maps and some special logic. I'm creating hundreds of objects in seconds. This destroys performance.

Even hitting the play button takes a while, and it's pretty hard to "exit" play mode, as it's basically 1 fps.

How should I go about culling everything not in the camera view. I don't understand any logic around the camera's view within C#.

If I knew more about how I could access the actual location and size of the camera's view, I could probably do something along these lines.

... {
    for (int y = 0; y < height; y++) {
        Vector3 pos = new Vector3(-width / 2 + x + 0.5f, objectHolder.transform.position.y, -height / 2 + y + 0.5f);
    
        // Imaginary If Conditions Ahead

        if (pos.x <= CameraViewMaxX && pos.x >= CameraViewMinX && pos.y <= CameraViewMaxY && pos.y >= CameraViewMinY) {
            Gizmos.color = (map[x, y] == 1)? Color.white : Color.clear;
            Gizmos.DrawCube(pos, Vector3.one);
            if (map[x, y] == 0) {
                Instantiate(block, pos, objectHolder.transform.rotation);
            }
        }

        // Back to Normal
    }
}

I don't know what direction to go in, and I don't know how to physically implement this into my game.

I know that I'm only supposed to load blocks in the view, like Terraria or Deepworld. That's the only reason those games run smoothly. It's because of the culling.

enter image description here

Puck
  • 2,080
  • 4
  • 19
  • 30
Mister SirCode
  • 1,575
  • 14
  • 31
  • look into [object pooling](https://gamedev.stackexchange.com/questions/148275/why-should-i-always-consider-creating-and-using-object-pools-instead-of-instanti) – Ruzihm Jul 01 '20 at 06:59
  • And maybe [this](https://stackoverflow.com/questions/42895445/unityhow-to-check-if-area-inside-camera-view). – Iggy Jul 01 '20 at 09:02
  • aint unity does frustrum culling by default? – Menyus Jul 01 '20 at 12:16
  • @Menyus I guess not... Because my amd ryzen 2700 and nvidia rtx super 2080 ti... yeah... those things are DESTROYED just tapping the play button. Maybe theres a setting that does it by default... but culling wont cut it. I need to only allow objects to be instantiated within the camera in the first place – Mister SirCode Jul 01 '20 at 14:33

0 Answers0