Polarith AI
1.8
Unity Pathfinding

front-end: AIMUnityPathfinding
inherits from: AIMPathfinding

The Unity Pathfinding component acts as an adapter between Polarith AI and Unity's Navigation and Pathfinding system. When you have already set up an Unity NavMesh in your scene, you need to add this component for integrating Polarith AI in your application. The simplest method to achieve a result is to setup an agent having a Follow Waypoints behaviour for interacting with the points computed by Unity's pathfinding. As long as the DestinationGameObject is set properly, an appropriate path leading to the target is calculated at runtime.

In detail, Unity Pathfinding creates a dummy NavMeshAgent with all fields set to a neutral value such that no further transformation interactions are done. So the NavMeshAgent is only used to asynchronously request the calculation of a path based on the scene's NavMesh. The conditions for (re-)calculating paths can be controlled through the Validator mechanism provided by Polarith AI. All available validators are listed in the property section below.

Note, we recommend to attach the Unity Pathfinding component to a (child) game object which has got a separate transform with respect to the Polarith AI agent. This way, the utilized NavMeshAgent cannot influence the agent (Context) transform regardless your Unity version.

Properties

This component has got the following specific properties.

Property Description
PointCount Shows the number of points contained in the path (editor only).
Points Displays the point coordinates of the current path. Due to performance reasons with respect to Unity's editor, only the last 50 points are shown. In code, you can use the method GetPoints to obtain the current point data.
DestinationGameObject The final target the path is leading to. If none is set, no path can be calculated. Note that the Destination can also be set directly via scripting.
DistanceValidator If enabled, this validator checks the distance of the agent to the path (nearest edge). If this distance is greater than the specified MaxDistance, the path is recalculated.
TimeValidator If enabled, this validator enforces a path recalculation after the given ElapsedTime has passed.
TargetValidator If enabled, this validator tracks the position of the DestinationGameObject. If the positional difference is greater than or equal to the set MaxDeltaPosition, then a new path is recalculated.
NavMeshValdidator If enabled, this validator triggers a path recalculation whenever the NavMeshAgent requests one, e.g., if the AreaMask has changed.

Preview

Remarks

Since the Unity Pathfinding component is an adapter, the actual path calculation is done by Unity and all features like AreaMask can be used. Of course, using the NavMeshAgent as underlying technology has some consequences:

  • You still have full control over the NavMeshAgent properties. However, most of them do not make sense in combination with our system. On the one hand, the whole obstacle avoidance mechanism should be handled by Polarith AI and not by Unity's NavMeshAgent. On the other hand, properties like AreaMask can still be used for setting up your scene.
  • In combination with a Rigidbody and an editor version prior to Unity 5.6, we noticed small influences on the transform of the NavMeshAgent's game object. So in general, we assume that these effects are not wanted. Thus, the best practice for setting up an agent is to add an extra game object with Unity Pathfinding attached. We recommend the following hierarchy:
    • Character (Rigidbody and Controller components)
      • Model (Sprite, Mesh, etc. components)
      • AI Agent (Context component and Follow Waypoints behaviour)
      • Pathfinding (Unity Pathfinding and NavMeshAgent component)

For further reference, see the corresponding Unity Manual page.

Imprint