skip to Main Content

Custom Editor Properties

Grid Configuration

This section allows you to configure the grid irrespective of its appearance or usage. Basically, these properties define the number of cells, territories and their shapes.

Terrain: assign your current terrain or root of group of objects that represent your terrain. TGS can work with Unity standard terrain or with any other mesh.

When using TGS on mesh-based objects, additional options to filter the objects will be shown:

  • Objects Name Prefix: allows you to enter a prefix string to filter the objects by name.

  • Objects Layer Mask: optional layer mask filter.

  • Search Global: when enabled, objects that meet the criteria above in the entire scene will be included. Otherwise, only children of the gameobject selected will be included.

  • Topology: this parameter defines the grid overall shape. You can choose between irregular (which uses a highly optimized voronoi tesselation algorithm), boxed or hexagonal type.

  • Territories and Cells: each grid has a number of cells and OPTIONALLY a number of territories. A territory contains one or more cells, so you will always have more cells than territories (or same number).

Note that adding territories will make the system slower with a high number of cells. To prevent lag during runtime while creating the neccesary meshes you can pre-warm the geometry using the API. More on that later.

  • Curvature: if your grid has 100 or less cells, you can apply an optional curvature. Note that using this parameter will x3 the number of segments of the grid.

  • Relaxation: this option will make irregular shapes (Voronoi) more homogeneous. Basically, it iterates over the voronoi calculation algorithm weighing and modulating the separation between cell centers. Each iteration will redo the voronoi calculation and even it’s been optimized that means that mesh generation times will go up with each relaxation level.

  • Roughness: this option will determine the level of gripping of the grid to the terrain. The greater the value, more abrupt the grid will appear with respect to the terrain. You usually will want to leave this value to the minimum possible unless your terrain is quite flat (in that case, increasing roughness will reduce vertex count).

  • Seed: this parameter will allow you to recreate the grid with same disposition of cells. This option basically affects the random functionality.

  • Flat Cells: when enabled, cells will ignore any terrain slope and will just be planar/horizontal cells.

  • Max Slope: specifies the maximum slope or inclination of the terrain at the center of a cell. A value of 1 means no slope is considered hence cells will be drawn regardless of this value. Reduce to prevent cells hang over steep terrain or walls.

  • Max Height Difference: specifies the maximum height difference between a cell vertices. If his height difference is greater than this value, that cell will be hidden. Similar to Max Slope but it can produce better results since it takes into account each individual vertex altitude while the Max Slope only considers the normal at the center of the cell.

  • Minimum/Maximum Altitude: specifies the minimum/maximum altitude to draw cells. Useful to hide cells under water for example.

  • Mask: assign a texture in this slot to define cells visibility (alpha channel is used to determine visibility, where a=0 means that cell is invisible). An invisible cell won’t be highlighted unless the “Highlight Invisible Cells” option is enabled. Invisible cells do not participate in pathfinding either.

  • Territories Texture: assign a color texture to define territories shape or cell ownership. One territory for each different color will be created. Ensure you use solid colors (no smooth or gradients) in the texture. If you use Gimp, you can switch to Indexed Color and set a maximum number of colors, then switch back to RGBA and export the texture in PNG format. Optionally specify which color will be used as neutral, meaning those cell won’t belong to any territory.

Grid Positioning

As the grid is a phisically generated mesh, it needs to cover the terrain subtly and effectively. This means that there should be an adequate offset between the terrain geometry and that of the grid. But at the same time that offset should be the minimum possible so the grid stays below any content put over the terrain.

To achieve the best possible effect, Terrain Grid System includes several parameters that allows you to control precisely how the grid is positioned with respect to the terrain mesh.

  • Mesh Pivot: this parameter only appears when using TGS with custom meshes. By default, TGS expects the mesh local center to be 0,0,0 but some meshes may start off another local position. In this case, adjust the mesh pivot position until the grid shows centered on the custom mesh.

  • Grid Center / Scale: controls the size and scale of the grid on the surface its cover originally. For example, instead of covering th entire terrain, you can use these center/scale options to show the grid around a specific location of the terrain (see demo scenes for examples).

  • Depth Offset: this parameter control how much offset is applied to the shaders used by Terrain Grid System. This value affects the Z-Buffer position of the pixels of both highlight surfaces (Colored Depth Offset) and grid mesh (Mesh Depth Offset).

  • Elevation and Elevation Base: both values are summed to calculate the amount of displacement along the Y-axis. Elevation Base uses a numeric input entry format in the inspector instead of a slider to allow finer/greater height values.

  • Min Elevation Multiplier: mesh root gameobject, cells layer and territories layer are separated by a very small offset (about 0.01f) in the Y-axis. You can control the size of this offset with this multiplier. Usually, this value should be left at 1 but if you use a terrain mesh with a very big scale, this offset can result in a big shift upwards so this parameter can be useful to reduce that gap.

  • Camera Offset: apply a displacemenet of the grid towards the camera position. This displacement is dynamic, meaning that it will move the grid automatically whenever the grid or the camera changes position.

  • Normal Offset: this option will apply a displacement per vertex along the normal of the terrain below its position. It will make the grid “grow” around the terrain in all directions. Note that this is an expensive operation. You usually don’t need to use this parameter.

Grid Appearance

This section controls the look and feel of the grid system and it should be self-explanatory. However it’s important to know that activating either “Show Territories” or “Colorize Territories” (or set the highlight mode to Territory as well) will enable the territory mesh generation. So, if you don’t use the territory functionality, make sure all options regarding territories are unchecked to save time and memory.

Grid lines are drawn using custom shaders that allow you to specify a near clip and falloff. These properties should be useful for those situations where the camera is really near the grid (like in FPS):

To change the default clipping and falloff values, use the Near Clip Fade and Near Clip Fade FallOff sliders.

The Cell Fill Padding option can be used to enlarge or reduce the surface of a cell when it’s colored or textured.

Grid Behaviour

This section controls what the grid can do.

The first and most important field is the Terrain reference, which you should set to make the grid system start working with your terrain.

In addition to that, you may choose:

  • Selection Mode: choose between None, Cells or Territories.

  • Overlay Mode: choose between Ground or Overlay modes. The overlay mode will make the highlight surfaces to be displayed on top of everything. Not very fancy but it’s the fastest and prevents any visual artifact with complex terrains. The default option, Ground, will make the highlight surfaces to appear below any content put over the terrain, effectively seeming that it’s being painted over the terrain.

  • Respect Other UI: when enabled, grid interaction is ignored while pointer is over a UI element (only uGUI elements are supported, those under a Canvas root element, not immediate GUI or elements created from OnGUI() functions).

Grid Behaviour

This section controls what the grid can do.

The first and most important field is the Terrain reference, which you should set to make the grid system start working with your terrain.

In addition to that, you may choose:

  • Selection Mode: choose between None, Cells or Territories.

  • Overlay Mode: choose between Ground or Overlay modes. The overlay mode will make the highlight surfaces to be displayed on top of everything. Not very fancy but it’s the fastest and prevents any visual artifact with complex terrains. The default option, Ground, will make the highlight surfaces to appear below any content put over the terrain, effectively seeming that it’s being painted over the terrain.

  • Respect Other UI: when enabled, grid interaction is ignored while pointer is over a UI element (only uGUI elements are supported, those under a Canvas root element, not immediate GUI or elements created from OnGUI() functions).

Path Finding

This section controls the path finding behaviour.

  • Algorithm: choose among available algorithms:

    • MaxDXDY: use estimations based on horizontal/vertical distance to target. Produces more natural paths althouth not optimal.

    • Manhattan: produces jaggy paths.

    • Diagonal Shortcut: favours diagonals in path.

    • Euclidean: estimation based on the straight distance to target. Produces the optimal path.

    • Euclidean Non SQR: similar but don’t uses sqrt which makes it faster.

    • Custom1: experimental method.

  • Max Search Cost: the maximum path length.

  • Use Diagonals: if diagonals between cells can be used.

  • Heavy DIagonals: add an extra cost for diagonals, making them less frequent.

The Path Finding algorithm is very fast but TGS also includes an optimized variant of the algorithm for grids that have column count power of 2 (4, 8, 16, 32, 64, 256, …).

Check demo scene 12 for example on using Path Finding with Terrain Grid System. Also read the available APIs for using path finding feature below.

TGS provides you 4 options to define available paths:

  • CellSetCanCross: calling this method you can simply specify if a cell blocks any path or not. The block state can be used as a parameter in methods like FindPath or CellGetNeighbours, etc.

  • CellSetGroup: use this method to assign a cell to a custom group. You can later specify which groups are allowed when computing a path calling FindPath method.

  • CellSetCrossCost: defines a custom crossing cost when entering a cell.

  • CellSetSideCrossCost: defines a custom crossing cost for a givel cell and a specific edge with option to consider moving direction (ie. entering or exiting the cell through that edge).

Grid Editor

This section allows you to customize the cells in Editor time.

With the Scene View selected (not Game View), you can use the mouse to select any cell and change their properties.

Export Settings will create add a “TGS Config” script which serves as a container for all the settings and will load them when activated.

Reset will clear all cell settings and reverts them to default values.

Textures array is a convenient way to load several textures and use them quickly to paint several cells. Just click the “T” small buton to enable the “paint mode”. Once enabled, you can click several cells to assign the chosen texture.

You can have several “TGS Config” scripts added. To load a specific configuration just enable the desired TGS Config component or call “LoadConfiguration()” method of that script.

 

Back To Top