FAQ
beginner faqTerrain Grid System 2 · Troubleshooting & FAQ
How do I add a new Territory through code?
Use the TerritoryCreate method with a cell index:
// Create a territory containing a specific cell
Territory territory = tgs.TerritoryCreate(cellIndex);
See demo scene 26 for examples of creating and destroying territories at runtime.
How do I change the grid topology at runtime?
tgs.gridTopology = GridTopology.Hexagonal;
tgs.rowCount = 32;
tgs.columnCount = 32;
tgs.Redraw();How do I center the grid on the player?
// In Update or when needed:
tgs.gridCenterWorldPosition = player.transform.position;
See demo scenes 10 and 10b for working examples.
How do I color individual cells?
// Color a cell
tgs.CellToggleRegionSurface(cellIndex, true, Color.red);
// Remove the color
tgs.CellHideRegionSurface(cellIndex);How do I detect which cell the player clicked?
tgs.OnCellClick += (grid, cellIndex, buttonIndex) => {
Debug.Log($"Clicked cell {cellIndex} with button {buttonIndex}");
};Can I use TGS on a mesh-based terrain (not Unity Terrain)?
Yes. Add the TerrainGridSystem component to the root of your mesh objects, or assign it via the Terrain property. Use Objects Name Prefix and Objects Layer Mask to filter which meshes are included.
Can I use TGS without a terrain (flat 2D grid)?
Yes. Use GameObject > 3D Object > Terrain Grid System to add a standalone grid that is not attached to any terrain.
When enabling Grid Editor, I cannot select any cell
Ensure Gizmos are enabled in the Scene View toolbar. Cell selection requires gizmo rendering to be active.
Does TGS support multi-terrain setups?
Yes. Enable the multiTerrain property. TGS will project the grid across multiple adjacent terrain tiles.
My question is not covered here
Please visit the Kronnect Support and post your question. Our team will respond shortly.
Is this asset compatible with Unity 6?
Yes. All Kronnect assets are fully compatible with Unity 6. The minimum supported version is Unity 2022.3 LTS, and this includes Unity 6 and any newer releases.
How do I double the size of hexagonal grid cells in terrain-grid-system?
For hexagonal and box grid types, use tgs.gridScale *= 2; to double the size of cells. Setting cellSize to a Vector2 will calculate the correct gridScale automatically. Note: this does not work for irregular grid types.
Why is only 1/4 of my terrain being rendered when I scale the grid?
Ensure your terrain GameObject has a scale of (1,1,1) rather than (2,2,2), as non-unit scales can cause rendering issues. Also verify you're using the latest version of TGS. If the grid still doesn't cover the entire terrain properly, use the reset buttons in the inspector to reset the center and scale, or ensure the terrain mesh resolution is set appropriately (greater than the base 1000x1000).
What are the main methods for getting cell positions and heights in terrain-grid-system?
Use tgs.CellGetAtPosition(position, worldSpace: true) to get a cell at a specific position, tgs.CellGetPosition(cellIndex) to get the position of a cell, and tgs.terrain.GetInterpolatedHeight(worldPosition) to get the height at a world position.
How can I get the GameObject (surface) for a specific cell in the terrain grid system?
Call the CellGetGameObject() method passing the cell index you want. The surface is created dynamically if needed and returned by that method. Reference the terrain grid system object and use this method in your scripts.
When calling CellDestroyBorder on cells that have custom borders created with CellDrawBorder, the regular cell border also disappears. How can I remove only the custom border without affecting the standard cell borders?
CellDestroyBorder should only remove custom borders and not affect the general cell borders, which are rendered as a single mesh for all cells rather than per-cell. If the regular borders disappear after calling CellDestroyBorder, this may indicate an issue. Check the console for errors. As a workaround, ensure the grid has been drawn at least once before calling CellDestroyBorder (the issue only occurs if the grid hasn't been drawn previously).
Cell highlighting works in scene mode but not in game mode, and mouse detection returns -1. What could cause this?
Check if the 'Respect Other UI' option is enabled, as a canvas might be blocking interaction. If that doesn't work, test the grid in an empty scene to isolate the issue. If it works in an empty scene but not in your main scene, verify you have selected the correct camera for the grid.
How can I create visual outlines or borders around districts in the terrain grid system?
To have an outline around districts, create a territory and assign the cells to it. Alternatively, if you don't need an outline, you can toggle cell colors or textures to visually distinguish districts or groups without using territories.
What does the maxSearchCost parameter do in FindPath, and how is it calculated?
maxSearchCost limits the total path length based on crossing costs. It returns paths where the sum of all cell crossing costs does not exceed the specified value. By default, each cell has a crossing cost of 1, so maxSearchCost: 3 returns paths of maximum length 3. If no path exists within that cost limit, it returns null.
When using OnPathFindingCrossCell, should the callback return the base cost of a tile or only the additional cost?
The callback should return only the *additional* cost, not the base cost. The base crossing cost of a cell is already factored in by the pathfinding algorithm. Only return extra cost on top of that (for example, penalties for difficult terrain or obstacles).
How do I extend the Cell or Territory class to add custom functionality without losing the original code when upgrading the asset?
Use a partial class in C#. Create public partial class Cell : AdminEntity { } in a new file. Partial classes allow code to be split across multiple files, so your custom code in separate files won't be replaced when you upgrade TGS.
When extending the Cell class, I lose access to original properties like index and can't pass the Cell object to methods like CellGetIndex. How should I properly extend Cell?
Instead of directly extending Cell with public abstract class Cell, create an intermediate class that inherits from Cell: public abstract class NewCell : Cell { }. This preserves access to all original Cell properties and methods while allowing you to add custom functionality.
How can I prevent territory/grid lines from appearing below the terrain when using higher roughness values?
Use the 'Mesh/Cell Offset' sliders in the inspector to adjust the depth position of the grid lines. These sliders raise the lines up to render above the terrain surface, preventing them from appearing below it.
Why does CellGetInArea return 0 cells with checkAllVertices=false but 4 cells with checkAllVertices=true for an object spanning 2 cells?
The method uses collider or renderer bounds (which are axis-aligned). With checkAllVertices=false, it only checks if the center of cells is inside the bounds. With checkAllVertices=true, it checks if any vertex of the cell is within bounds. If you're getting unexpected results, verify your colliders are correct, as corrupted colliders (e.g., from copying objects between interfaces) can cause this behavior. You can also use the padding parameter to expand or reduce the bounds size.
When enabling 'Regular Hexes' option, how do I restore the previous behavior or reset the scale when switching topologies or disabling the option?
When enabling Regular Hexes, the asset computes the scale automatically and lets you specify the hex width. Changing to another topology or disabling regular hexes doesn't automatically restore the scale to default (1). You can manually reset the scale by clicking the 'Reset' button next to the Scale field.
How can I use Terrain Grid System on a dedicated server build to determine which region each player is in without errors related to mouse input and shaders?
Disable the Mesh Generation option in TGS settings. This will invalidate input handling as well, allowing the asset to run properly in server-only mode without requiring mouse input or shader resources.
How do altitude filters affect cell visibility and mesh generation in the terrain grid system?
The minimum and maximum altitude filters hide cells outside of the range by not generating meshes for them, though the cells are still internally generated. The cell.visible property will be false for filtered cells.
How can invisible cells be excluded from pathfinding calculations?
Disable the 'Include Invisible Cells' option in the inspector to ignore invisible cells during pathfinding. Note that this will return a cell-based line rather than a continuous path.
What does the clearance option do in pathfinding?
The clearance option ensures there is space of x cells on either side of the path, but it does not make the path itself wider. If you need a path that is 2 cells wide, consider widening the grid resolution instead.
Why are Voronoi cells not generating with sufficient variation when using different seed values?
Make sure you're passing different seed values to the Voronoi generation. Additionally, check if relaxation is enabled - try setting relaxation to 0 if cells are too similar. Also ensure the Voronoi data is not baked; clear any baked data first so the grid regenerates based on the random seed.
Custom attributes and code that colors cells are not being called after clearing baked Voronoi data. How can this be fixed?
Move your custom attribute initialization and coloring code from Awake to the Start method instead. TGS may not have finished generating the grid during Awake, so using the API in Start ensures the grid is fully initialized before your code attempts to access or modify cells.
How can I manually override the visibility of specific cells that are hidden by altitude rules, and have those changes persist when reloading the scene?
The visibleByRules property controls visibility based on grid settings (altitude, slope, height difference, etc.). To override this for specific cells, you need to save the visibility state of individual cells to a data structure (such as a dictionary or custom serializable class) and restore it when the scene loads. Disable the altitude rules if you want manual control, then programmatically set cell.visible for the cells you want to show and persist this data outside the grid system's automatic rule evaluation.
Do the TerritoryVertexPosition and the cell returned by CellGetAtPosition always belong to the same territory?
Probably not, since edges are shared between territories. To ensure a position falls within a cell belonging to the territory, you can add a tiny shift towards the center of the territory. Alternatively, get all cell centers in the territory to which the vertex belongs, find the nearest one to the vertex point, and scale the vertex position towards that cell center.
How do I make the terrain grid system scale properly with the camera in a 2D orthographic view?
The grid is a world-space mesh and doesn't automatically scale with camera changes. For 2D orthographic cameras, use the FitToScreen() method: grid.FitToScreen(cam, margin, keepAspectRatio). Alternatively, manually adjust the grid size and center using: float height = cam.orthographicSize * 2f; float width = height * cam.aspect; grid.SetSize(new Vector2(width, height)); and then reposition the grid center to match the camera position.
I have a question not covered here
Please visit the Support Center and use our AI Support Assistant to get answers. If the issue persists, submit a reproduction project so we can investigate further and help you.
Suggest an improvement
Help us improve this documentation page.