Disable AI or stop AI Tick based on distance for bots

I was wondering if there was a way to have AI disable or stop ticking once the AI is out of range, and re-enable or start ticking once in range. Currently, the FPS is unbearable and hiccups from 100+fps (Standard without the AI bots) range down to 20fps once every second.

My attempts began by creating a “bEnabled” variable that was disabled by default in the character blueprint and AI controller for the bots.I came to this conclusion that this would be a solution because when I disabled the spawners (Spawners didn’t cause the FPS to hiccup, only occurred once the bots were active and spawned). So I used an interface, and a call every 3 seconds. The player character calls via timer event all objects of class “bot parent class name”, and does a distance check. The interface calls correctly, and the message is received, checked via print strings. However, the AI, when disabled at the start, does nothing. When enabled from the start, we are back at square one.

The second attempt I did was to include a possess ai controller call when the interface called for the ai to be re-enabled and an unpossess ai controller call when the ai was to be disabled. This yield the same results.

Third attempt, I disabled the player characters distance check. When the AI bEnabled was true, the AI functioned, when it was disabled it didn’t but the FPS hiccup was still present.

We have a large amount of individual AI characters on a large map. The FPS just takes a massive hit, and using “Stat StartFile” we had this

Highlighted is what is believed to be the issue. I don’t know how to fix that nor what it pertains to (How the Ai on the navigation moves maybe?)

Here is a Mega link to our Profiler files

[Mega.nz][2]

How did you set up your bot actor? I would recommend you to remove, or at lease SetAutoActive to false for those component you don’t need, such as camera, which eat lot and lots of resources.

So I SetAutoActivate to false and other unnecessary components, but the hiccup was still present. The bots are set up with timer events rather than ticks, and those are set to repeat between 0.2-0.8 seconds. We have about 4 of those timer events set up, and they aren’t intensive calculations. Just checks for intergers and floats so they don’t exceed or thirst/hunger meters.

Also the bots use behaviour trees, and ai perception hearing, damage, and sight

How about you disable all of the active component, then slowly active each one and check which one used the most resource. The same with all those timer.

I’ll give that a shot and see if I can determine the issues. Another thing is I think the only way I can achieve what I want is to spawn ai within a distance every, minute for example, and despawn the ones that are out of the range unless they have been tagged/marked by the player