Integrate Custom Pathfinding Solutions
By default, the RTS Engine uses Unity's navigation mesh to handle pathfinding for units. There is also an integration package for the A* Pathfinding Project asset that you can import if you wish to use that asset to handle pathfinding.
However if you would like to integrate a different pathfinding system then this guide is for you. This guide goes through what components and classes you need to add to your project to plug a pathfinding solution to the RTS Engine. Details regarding the methods and properties that need to be implemented can be found in the API documentation pages linked below.
1. Implement IMovementSystem
The Movement Manager component is independent of any pathfinding solution. But in order to hook it up to a pathfinding system, it requires to have a component that implements the IMovementSystem interface attached to the same object.
The interface has one method: TryGetValidPosition. It is used by the Movement Manager when searching for a valid movement path destination by sampling an area.
An example of this interface's implementation for Unity's navigation system can be found in the NavmeshMovementSystem class.
2. Implement IMovementController
The Unit Movement component is responsible for moving units to their path destinations and is independent of any pathfinding solution. In order to hook it up to one, a component that implements the IMovementController interface must be attached to the same object.
The interface includes methods and properties that allow for preparing path calculations and communicating directly with the component attached to the unit that handle the actual pathfinding. Please refer to the interface's API documentation for more details about the properties and methods that need to be implemented.
An example of this interface's implementation for Unity's navigation system can be found in the NavMeshAgentController class.
3. Handling Building Obstacle
Each pathfinding solution should come with a component that renders an area to an obstacle that units can not move through. Buildings in the RTS Engine make use of such a component. When placed, the area occupied by each building is non-movable for units. This area only becomes non-movable once the building is placed and not while it is still in its placement phase.
A dedicated component must be attached to the building prefab that allows it to control enabling the pathfinding obstacle only when the building is placed. An example of this for Unity's navigation system can be found in NavMeshBuildingObstacle class.
A simple solution here would be to extend the BaseBuildingObstacle generic class which takes the type of the pathfinding solution obstacle component and internally handles enabling it only when the building is placed.