How can I make AI have less impact on performance?

What does your behavior tree look like or is it the one in the tutorial?

1 Like

Exactly the same as in the tutorial

Hello,

I have created a basic AI (This one ā†’ [UE4 Wiki][1]). And as shown in the images, it has a massive impact on the performance after placing circa 30 low poly AI. How can I drasticly improve the performance?

Thank you in advance and kind regards,

Eric

With the AIcontroller the fps went from 14 to 28 fps. So still sub-optimal.

Hardware is fine

stat DumpFrame -ms=0.1 shows nothing

Just to make sure, have you isolated that itā€™s the AI logic that is causing the performance problems? E.g. if you set the controller to the default AIController and spawn 30 of your pawns do you still experience low fps? You can also use ā€œstat DumpFrame -ms=0.1ā€ from the documentation to get a better idea where the CPU time goes. It basically shows time and the call count for different methods.

Otherwise provided that your hardware is good enough it sounds like it should be reported as a bug or maybe a feature request since youā€™re taking the example straight from the wiki.

Iā€™m not really sure what my be causing the issue but a drop to 28 fps sounds like there is some other problem as well apart from the AI. The default AIController does nothing basically. Still sounds very expensive though to run the behavior trees.

With risk of stating the obvious, make sure you run ā€œstat DumpFrame -ms=0.1ā€ when the game is running. Otherwise I donā€™t know what the problem with that command would be.

How can I be sure that I ran stat DumpFrame -ms=0.1 correctly? The FPS does is not changing when stat DumpFrame -ms=0.1 is entered in the commandline wile running the game.

What is does is that it prints some kind of call trace log in the console output.

The stats on the screen clearly show that the cause of your fps drop is character movement. Iā€™m surprised itā€™s that much to be honest, but nonetheless thatā€™s your cause. Thereā€™s couple of things you might try. First of all see if you really need CharacterMovementComponent for our AI. Itā€™s pretty expensive, raw PawnMovementComponent is a lot cheaper (but has less features as well).

Upcoming 4.8 is shipping with ā€œnavmesh walkingā€ as a optional character movement mode. This is a lot cheaper, but requires you to have navmesh on your maps, and itā€™s quality is only as good as your navmeshā€™s precision.

One other thing, you might want to disable overlap checks for your pawns (set GenerateOverlapEvents to false it pawnā€™s components). Overlap checks do show in your perf stats as well.

Cheers,

ā€“mieszko

1 Like

Hey Mieszko, you mentioned a raw ā€œPawnMovementComponentā€, sounds really interesting, but where is it? I canā€™t find itā€¦ Profiling tells me that the Character Movement Component is taking 650ms, so itā€™s a bit too much I think, and I donā€™t need many features, no jumping or anything else fancy, just being able to move from A to B and use the navmesh to find the path. I only have 300 AIs at the moment, I would like to get it smooth, and 650ms does not look smooth :slight_smile:

Iā€™m also interested in this, does the CharacterMovementComponent still have that big performance impact?

1 Like

ā€œthat bigā€ is relative to the machine its running on. It hasnā€™t improved really that much, I have done some extend testing on it in recent versions.

400 AIā€™s

  • Without AI: 11MS
  • Without Movement: 14.5MS
  • PawnMovement: 18MS
    (acceptable performance, but the
    quality is not suitable)
  • CharacterMovement: 28MS (Bad
    performanceā€¦)
  • CharacterNavmeshwalking: 27MS
    (literally just as bad)

In conclusion Iā€™m still looking for a suitable AI_Movement Solution. I hoped the MOBA AI Twitch stream would give some improvement tips in that regrads, but when I saw they just used plain character movement I quit the stream.

Thanks for these stats. Quite useful.

Iā€™ve noticed that character movement component is just not viable for large numbers of AIs as well. Itā€™s fine and dandy if you just want to have a couple guys running around, but for anything large scale you need an alternative.

Iā€™ve been looking at custom variants of the ā€˜floatingā€™ movement component for my game , (as it is mostly underwater) but I can see it turning into abit of a rabbit hole if I want to have my pawns also walk on land , etc.

Epic, can you make a less expensive variant of character movement for large scale AI use? pretty plz?

1 Like

We have an average of 200 characters at one time in Paragon, and we donā€™t experience huge perf hits. Using navmesh walking is the key here but it works only if thereā€™s navmesh where AI is moving.

Yeah, thatā€™s not gonna work for me as Iā€™m using a custom pathing system for my underwater navigation (navmesh doesnā€™t work in fully 3d environments) :confused:

1 Like

Is there a viable way to calculate the path (with path finding) on a separate thread and once having the path(points array I suppose) to feed it up to the AIController to narrow down the Pathfinding calculations ?

Iā€™m struggling with ai nav mesh and vr. canā€™t even get 60 ai in without it going down to 40 fps

I would be very curious to see your setup that has 200 performant AI. I have stripped everything down as much as possible and 200 AI seems to cost about 8ms. Could you list out the key setup elements that allow for this performance?

I am in the same situation. 30 AIs and my game is done. An AI movement tutorial, article, even a sentence about how to go about getting 200 AIs on screen using navmesh would be great for relative newcomers like me making Twin Stick shooters etc

I am in the same situation as well. Really need to spawn around 200 AI characters roaming around the level to give the environment a crowd feel. Any guidance in this direction would be appreciated