Performance Issues JobRepairEnd

Hi, I need help figuring out what I’m doing wrong that’s causing a lot of time to be spent on these calls related to “JobRepairEnd”. See images


.

I have a 2D grid graph that’s 120 x 95 nodes and node size 0.3. It’s actually a wide open space with no obstacles yet, so collision is disabled. I also have an RVOSimulator (see

).

I also have agents that use FollowerEntity and AIDestinationSetter (see image

). This seems to work fine, but when the game reaches multiple hundreds of agents, FPS drops to single digits. “JobRepairEnd” seems to be a big culprit, but I’m unsure what is causing it.

Some things that seem suspicious are:

To stop an agent from moving, I set FollowerEntity.isStopped to true and set the path to null like so:

    public override void ToggleMovement(bool is_toggle_on) {
      if (!_path_ai) {
        return;
      }
      _path_ai.isStopped = !is_toggle_on;
      

      if (_path_ai && _path_ai.hasPath && !is_toggle_on) {
        _path_ai.SetPath(null); 
      }
    }

Should I not be clearing the path like this?

Another potential issue is that this is a horde game and when the player is surrounded, only a handful of agents can reach the player, but the hundreds of other agents still try. Should I be handling this somehow?

Lastly, this is a 2D top-down game where I don’t want any rotation (because I instead use different sprite animations for directions), so I turn off rotation when an agent spawns in. Could this be causing issues with path calculations?

  private void OnEnable() {
    _ai.updateRotation = false;  
    gameObject.transform.rotation = Quaternion.Euler(0, 0, 0);
  }

Thank you in advance for any guidance!

Hi

If you set the agent’s path to null without also setting ai.autoRepath.mode = Never, then the agent will almost immediately recalculate a new path, which has some overhead. Could this be the cause?
Also make sure that script debugging is not enabled, that burst compilation is enabled, and that deep profiling is disabled.
The timeline view in the profiler can also be useful to check what’s happening on other threads.

One thing to note. Since the game is running so slowly, the system will simulate the agents more than once per frame to keep the movement stable. This, in turn, makes the game run even slower (but only up to a point).

Got it, I checked and I already have those three settings correct (burst compilation enabled, script debugging not enabled, deep profiling not enabled).

But, I’m having trouble setting the repath mode. When I try _path_ai.autoRepath.mode = AutoRepathPolicy.Mode.Never;, I receive the error Cannot modify the return value of 'FollowerEntity.autoRepath' because it is not a variable, which makes sense because it looks like FollowerEntity.autoRepath is of type ECS.AutoRepathPolicy.

Is this the correct way to set the mode instead?

private Pathfinding.ECS.AutoRepathPolicy _never_policy;

private void Start() {
  // Cache a new policy.
  _never_policy =  new Pathfinding.ECS.AutoRepathPolicy();
  _never_policy.mode = AutoRepathPolicy.Mode.Never;
}

and then

_path_ai.autoRepath = _never_policy;

Also, thank you for the tip on checking the timeline view. I am seeing a lot of “JobRepairPath” calls and under them calls to things like GetNextCorners, SetFunnelState, and Splice. See images:


In this frame, I have several hundred agents, so does this timeline look usual for that amount? There’s this line in the FollowerEntity docs that mentions path repair, so perhaps the destination is being updated too often (e.g. when I set path to null)?

For example, it goes to great lengths to ensure that the reachedDestination and reachedEndOfPath properties are as accurate as possible at all times, even before it has had time to recalculate its path to account for a new destination. It does this by locally repairing the path (if possible) immediately when the destination changes instead of waiting for a path recalculation.

Do you have a screenshot of how your paths look? This does seem pretty slow to me, but could be reasonable if your paths are really long.

Not quite. Do:

var policy =  ai.autoRepath;
policy.mode = AutoRepathPolicy.Mode.Never;
ai.autoRepath = policy;

that way, you’ll not discard any other settings in the policy.

Yes, here: