Ticking and Optimizations
Overview
AI can quickly become a performance bottleneck. Most heavy, albeit necessary, calculations are physics queries such as long raycasts. It is therefore advised to not perform such checks until absolutely necessary.
Physic Queries
In some situations it is possible to replace raycast queries with NavMesh line of sight checks. Although these are relatively slow, they are still faster than raycasts; an example implementation of this can be found in the position finding SetWeaponRangeDestinationAIAction
and in the SensorEyes
which filters out agents based on several parameters and sorts them before doing any raycasts.
Behaviour
AI behavior execution has been optimized by scheduling one AI update by tick. More specifically, only one AI per simulation frame will update its HFSM and sensors. Animation states are always running for all AI Agents to ensure movement and rotation fluency. This also means a higher number of AI controlled agents will result in agents seemingly becoming more dumb. In reality, the degradation happening when increasing the amount of AI agents in the game from one to eight is hardly noticeable.
The updating / tick scheduling behavior can be changed in the AI
component if the default settings are not desired.
Sensors
Sensors are optimized by specifying at which interval of the AI tick counter a sensor should be updated (e.g. every 3rd AI tick).
Back to top