Polarith AI
1.8
Determinism

This page is all about determinism and how to achieve that with Polarith AI. First things first, achieving true deterministic AI behaviour is never easy but possible, although it is not as comfortable as just using our components as they are in a plug-and-play manner. Please, take into account that there will always be a little extra effort compared to non-deterministic approaches.

Whenever possible, consider using a non-deterministic AI system.

Why Determinism?

Before we will have a look at how to achieve determinism, let's discuss why or whether you really need such an approach. In terms of comfort, algorithm design, performance and ease of use, you would better be off with a non-deterministic system as Polarith AI is by default. But especially for multiplayer applications, determinism can help you to dramatically reduce the network traffic and the need for high-end server infrastructures. In most use cases, the best way to go would be a hybrid system which is non-deterministic on the client-side in situations where this is allowed and deterministic only in situations where this is a hard requirement. For example, cosmetic visualizations in your virtual world would most likely be non-deterministic, as against gameplay-relevant actions should be deterministic.

However, there are also parts in the field of (game) AI which are extremely hard to be made deterministic in real-time at all. For example, pathfinding is always a problem when it comes to deterministic client-side approaches. That is why a proper hybrid solution would most likely compute the pathfinding on the server and stream the data to the client where a local steering approach ensures that waypoints are reached appropriately.

Prerequisites

For achieving true AI determinism, the rest of your development infrastructure and application need to support this, too. As a starting point, you should have a look at lock-step systems and deterministic client-side code in general. If you managed to integrate a deterministic world right into your application, have a look at the next section for implementing Polarith AI in a deterministic manner into your scenario.

Since Polarith AI (Pro) utilizes Unity's pathfinding for generating waypoints to be followed, and as already indicated in the section above, there are some components respectively behaviours which will never work in a deterministic way. Especially the Unity Pathfinding component in combination with the Follow Waypoints will break determinism by all means. Of course, predefined Linear Path data is completely fine to use in combination with the Follow Waypoints behaviour. So, if you are lucky and found a decent deterministic pathfinding solution working in Unity, you can integrate it rather easily by deriving from AIMPathConnector and injecting your custom path data. This way, your deterministic pathfinding would still be compatible to Follow Waypoints which would then be deterministic as well.

How to Achieve Determinism

Let's suppose you have already implemented a completely deterministic world and application infrastructure. So far so good! Then, the following guidelines will help you achieve true determinism with Polarith AI as well. Good news: The core Steering algorithms of Polarith AI are already deterministic by its very nature. Yeah! Bad news: For a deterministic final result, you may not use the components straight-forward as they are because concerning determinism, your greatest enemy are Unity and its internal update mechanisms. Now, let's deterministify your use of our technology.

  1. Ensure that the AI world is perceived deterministic. To do so, disable the Steering Perceiver game object, which forces you to call the Awake and Update methods of AIMSteeringPeceiver yourself and in synchronization with your deterministic client-side code, e.g., your lock-step system.
  2. Make sure that the AI updates are in synchronization with your deterministic client-side code. For that, you may not use the Perfomance component (Pro only). Instead, you need to derive from AIMContextEvaluation in order to provide your own main loop for updating the AI in synchronization with your deterministic client-side code. Every component inheriting from AIMContextEvaluation which is present within a scene will deactivate all automatic AI updates. This forces you to iterate through all available ThreadedComponents and NonThreadedComponents yourself calling the Evaluate method for each component respectively agent in synchronization with your lock-step or deterministic client-side system.
  3. Do not use the Unity Pathfinding component as input for the Follow Waypoints behaviour because this will break determinism by all means. That is due to the fact that we use Unity's pathfinding as underlying technology which works not deterministic at all.
Imprint