docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Call Grid functions from Unity Jobs

    Use GridData and GridUtility to call the coordinate conversion functions of a Grid component from inside a Burst-compiled job.

    The Grid and GridLayout components are managed types, so you can't access them from a job. GridData is a blittable copy of the grid's layout, cell size, cell gap, and cell swizzle. GridUtility is a static, Burst-compatible class that uses a GridData to perform the same coordinate conversions as the Grid component.

    Use GridData and GridUtility in a job

    Follow these steps:

    1. On the main thread, create a GridData from a Grid or GridLayout component.

      var gridData = new GridData(myGrid);
      
    2. Pass the GridData into your job by value. To convert between cell space and world space, also pass the TransformHandle from the Grid's tilemap.

      [BurstCompile]
      struct MyGridJob : IJob
      {
          public GridData gridData;
          public TransformHandle transformHandle;
          public NativeArray<float3> worldPositions;
      
          public void Execute()
          {
              var cellPosition = new int3(2, 3, 0);
              GridUtility.CellToWorld(in gridData, ref transformHandle, in cellPosition, out var world);
              worldPositions[0] = world;
          }
      }
      
    3. Schedule the job as normal.

    Inside an entity tile job delegate, the TilemapDataStruct parameter exposes a transformHandle property you can pass to GridUtility. For more information, refer to Create a custom entity tile.

    Note

    A GridData is a snapshot. If you change the cell size, cell gap, cell layout, or cell swizzle of the Grid component on the main thread, create a new GridData before scheduling the next job.

    GridUtility methods

    Each GridUtility method matches a function on the Grid or GridLayout component. For the parameters and return values of each method, refer to the equivalent Grid or GridLayout function in the following table.

    GridUtility method Grid component equivalent
    CellToLocal, CellToLocalInterpolated GridLayout.CellToLocal, CellToLocalInterpolated
    LocalToCell, LocalToCellInterpolated GridLayout.LocalToCell, LocalToCellInterpolated
    LocalToWorld, WorldToLocal GridLayout.LocalToWorld, WorldToLocal
    CellToWorld, WorldToCell GridLayout.CellToWorld, WorldToCell
    GetBoundsLocal GridLayout.GetBoundsLocal
    GetCellCenterLocal Grid.GetCellCenterLocal
    GetLayoutCellCenter GridLayout.GetLayoutCellCenter
    CellSwizzle, InverseCellSwizzle Grid.Swizzle, Grid.InverseSwizzle

    Additional resources

    • Create a custom entity tile
    • Grid component reference
    • Job system
    • Burst compiler
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)