Performance optimization by not destroying actors

The following reports from a world partition environment with spatially loaded and unloaded actors, which is cleaned-up on unload by the Unreal Garbage Collector.

After awhile the performance went down and it probably came down to how to deal with killed game actors. Perhaps even down to a single variable storing the target reference, the exact reason is unclear to me. An AI query gives pointers that the Unreal garbage collection (GC) can become a bottleneck when too many actors are killed, and or to many things are destroyed.

So I have set a couple of things like a PatrolComponent to be destroyed on spawn which may have contributed to it. The optimization here is to only add those components to actual patrol actors.

But the smart thing appears to not destroy at all, or only rarely.

Here are a few steps to temp remove an actor from the scene / view until it is returned - fake-respawned. Notice, that the following may be different in your project.

Notice that the highlighted target variables are important to be emptied too, otherwise the AI may not act as expected, i.e. moving randomly since it still has an active target set.

And then we restart the behavior again, the function reset contains all the on begin called behavior tree settings - I briefly set an empty behavior tree, which may be redundant.

And at last

And that’s it, the basics of how to return a character actor to the game without destruction.