Search Unity

Question How to use Layer Cull Distances to cull distant parts of a Tilemap?

Discussion in 'Editor & General Support' started by akim330, Dec 20, 2022.

  1. akim330

    akim330

    Joined:
    Jul 29, 2021
    Posts:
    6
    In my 3D environment, I have a large Tilemap. I want to be able to cull parts of the Tilemap that are distant from the camera (>200 units away). However, I do have a very faraway skydome (1500 units away) that I don't want to cull.

    In order to accomplish this, I did the following: 1. Set the "Far Clip Plane" on the camera to 2000 so it is beyond the skydome. 2. Attach a script to the camera that on Awake, will set the camera's layer cull distance array. Specifically, set the element corresponding to the Tilemap's layer (called "Ground") to have a cull distance of 200:

    Code (CSharp):
    1.  public class CullingLayers : MonoBehaviour
    2. {
    3.      private Camera _main;
    4.      // Start is called before the first frame update
    5.      void Awake()
    6.      {
    7.          _main = Camera.main;
    8.          float[] distances = new float[32];
    9.          distances[9] = 200f; // Ground layer is the 9th layer
    10.          _main.layerCullDistances = distances;
    11.      }
    12. }
    However, when I go into Play Mode, my Tilemap is completely unaffected.

    As an experiment, I used this script to set the Player's layer cull distance to 1, and it successfully culled the player from the camera view. So I think the script does work. But it doesn't seem to be working with the Tilemap.

    Here is my Tilemap Renderer in the Inspector in case that's helpful (Note I've tried this with Mode set to "Chunk" and "Individual" and that didn't fix it):

    Screen Shot 2022-12-19 at 9.06.36 PM.png

    If anyone could help out with any advice, that'd be greatly appreciated!