Unreal Engine AI/NPC performance. How Open world games do it?

Hello,

I am making an Open World game with Unreal Engine for the past 2 years and i need some help or advice regarding activating and deactivating AI characters for an open world game.

The desired goals are the following:

1)Spawning 10.000 inactive AI actors across the level

2)Use behavior trees

3)Activate and deactivate the actors based on distance from a player

I have made a setup that can spawn 200 actors with reasonable fps and then activate and deactivate visibility,collision,tick and logic based on distance

My challenge is in goal 3

My benchmark is spawning 10.000 empty actors and that is giving me 120 fps

As long as i spawn and make these 200 AIs inactive my performance falls to 40fps

My problem is that i cannot determine what is left that still costs performance.

I am disabling the following:

1)Mesh Visibility

2)Collisions

3)Actor Tick

4)Stoping AI Logic

Are there any additional stuff i could remove in order to make the Actors cost close to Zero but still holding the variables ?

Thank you!

Hi, is there a reason why you don’t spawn and destroy the actors based on the distance to the player? So you could make a DataTable that holds a location (where your actor is) and an actor class (the class of the actor). You could add more variables like health and so on. Then you would have an array of that data inside of a blueprint and then spawn/remove them based on the distance of the location to the player.

Thank you for your answer. I cannot do it that way due to the fact that actor spawning/despawning is very expensive and it creates lagspikes

I know this is an old thread, and I might be wrong, but I think 10000 actors means 10000 draw calls every frame, whether those actors render or not. So the CPU needs to ask each actor if it’s going to draw each frame.