A search grid is composed of search cells with a fixed size (that can be chosen from the inspector).
Each search grid has a lower left corner and upper right corner coordinates that define areas that are searchable inside the map. A search allows to search for RTS Entity instances (Unit, Building and Resource).
Instead of linearly searching through all potential entities until finding the closest one that satisfies certain conditions, the search grid allows to search only areas (or search cells) within the search range and when the parameters are tuned, it proves to be much faster and performant that linearly going through all potential entities.
The GridSearchHandler is the component responsible for handling search requests from other component.
When creating a new map using the RTS Engine menu, this component is attached to an object called ‘MovementManager’.
- Lower Left Corner: Defines the lower-left corner of the search grid where search cells will be generated. The Y coordinate corresponds to the Z axis in the world coordinates.
- Upper Right Corner: Defines the upper-right corner of the search grid where search cells will be generated. The Y coordinate corresponds to the Z axis in the world coordinates.
- Cell Size: The size of each individual cell. Must be >= 1. The bigger the cell size is, the higher the amount of items to be searched with each search request will be. To deliver the best performance results, this value should be a compromise between the different search ranges that different RTS Engine components have (searching for attack targets for attack units or buildings, searching for target resources for the automatic behavior for resource collectors, etc..).
The Y axis in world coordinates is not considered by search cells. This means that if an entity’s position coordinates on the X and Z axis is inside a certain search cell’s, it doesn’t matter what the entity’s position on the Y axis is.
When selected, the GridSearchHandler component draws mesh cube gizmos that represent the search cells (where each cell is assigned a mesh cube) of the map so you can tweak the parameters and make sure that the whole map is included in the search grid.
- Gizmo Color: The color of the mesh cube assigned to each search cell.
- Gizmo Height: Where to display the mesh cube gizmos on the y axis in world coordinates.
Here’s an example of the drawn search cell gizmos: