My situation is that i have 750 NPCs(which is a blueprint child class inherits from the basic Character class) in the scene(a tall building), which has the basic ThirdPerson_AnimBP as its Anim Class and the SK_Mannequin as its Skeletal Mesh.When the game starts, all of the NPCs will run to the same target location.
I use the AI Move To event in the NPC class’s Event Graph to force the NPCs move to the target, shown as following:
For the light, particle and stuffs. I only use the default lighting which comes with the ThirdPersonGame template like this:
And there is no particle system in the scene.
When i start the game(as standalone game), my frame rate fell to about 10 in an instant. I use the STAT UNIT to check, it shows this:
I Know that means my cpu and GPU are the performance bottleneck. Then I check the CPU and GPU usage, which turns out during the game the CPU occupancy is only about 30%, and the GPU occupancy is even lower.
So i wonder if i can use more of my CPU and GPU’s power to run the game. OR should i change the way I drive the NPCs?
Any help would be appreciated!
Let me Know if u need more information about my situation!
Having 750 fully rendered, fully thinking, npcs is not a good idea in the first place. You’ll definitely need to find an alternative if you’re looking to have them all visible at once.
This’ll be an even bigger problem once you actually have advanced logic. Your CPU will spontaneously cease to exist.
To utilize more of a CPU, you’ll have to branch out into other cores/threads. I’m not sure if you can do this custom in blueprints, but most built in functions that do something like this are called “Async” functions. Though- this can only be done for things that don’t need any reference to anything that’s happening in the main game thread. Like if you needed the 10^10^10th digit of pi (unrealistic ik), instead of holding up the main thread while calculating (thereby freezing the game), you could have that running on an entirely separate thread with the main program just getting notified when it’s done.
This is simplifying, but it provides a general description.
Honestly I’m not sure if you can optimize 750 npcs running around since I’m not sure if you can put pathfinding on another thread. That is, unless you completely rework the navigation system and have a very very very specific game setup that would allow that.
You are likely hitting a CPU bottleneck. 30% CPU doesn’t really tell you everything, you need to know how many cores you have. For instance if you have 4 cores, 25% usage means a single core is maxed out.
You have to do less per frame. Likely reduce the number of NPCs. Use UnrealInsights to find out what is the primary bottleneck. Probably charactermovement. Look into more exotic optimizations or possibly MassAI (I don’t have experience with this).
I think reducing the number of NPC might be the best idea for me too, since i used to put 250 NPCs in the scene, the game ran pretty well. Then My teacher asked me to put 750…
Thanks Anyway. I am going to follow the link in your reply !