65k cleanup Slows Game to a Crawl

I am running in to an issue where I am getting 65k cleanup massages and then the game gets very laggy. This happens after running the game for 30 seconds. The game has 1 enemy that calculates a path every .5 seconds.

Is there a proper way to continuously calculate a path? At later levels in the game, there will be hundreds of enemies that will need to path find.

Hi

You cannot just be calculating one path every 0.5 seconds. Then to calculate 65000 paths would take about 9 hours. Sure nothing else is going on?

Here is my code:

private IEnumerator UpdatePath() {
	if (enemy.target == null){
		if (!searchingForPlayer){
			searchingForPlayer = true;
			StartCoroutine(SearchForPlayer());
		}
		yield break;
	}
	
	seeker.StartPath(transform.position, enemy.target.position, OnPathComplete);

	if (state == State.aggro) {
		yield return new WaitForSeconds (1f / updateRate);
		StartCoroutine (UpdatePath ());
	}
}

The updateRate variable is set to 2.

After posting this I found a snippet of code that was calling update path every frame. Which was the issue.

1 Like