Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

AI optimization

I need at least a hundred AI characters in my game. However this has a huge impact on performance. I know it's not the character models because having AIs without mesh impacts the performance just as much. Is there any known ways to reduce AI performance impact? I'm pretty new to Unreal so I don't know much about it's features. I do however know that you can use behavior trees to create AI behaviors. Right now I'm using blueprint for that so maybe that's the problem? The behavior is really simple though. It just moves the character on a nav mesh and updates the destination every 10th second. No tick calculations or anything. I've read somewhere that the character movement component is pretty expensive. Could that be the problem? Is there a good alternative component to use for movement instead? I know that Unreal has some kind of AI crown feature. Is this something I could use?

Product Version: UE 4.9
more ▼

asked Apr 01 '16 at 09:13 PM in Blueprint Scripting

avatar image

71 6 8 11

avatar image Black Phoenyx Apr 01 '16 at 09:22 PM

Are you using an AI Move To node or just adding input movement directly? Can you post a screenshot of your BP?

avatar image Olverine Apr 01 '16 at 09:36 PM

a couple of screenshots are a attached to this reply. As you can see, I use the AI move to node and now heavy calculations are done. No tick event or anything that I know is heavy on the performance.

capture.png (104.0 kB)
capture2.png (188.0 kB)
avatar image Mesothere May 02 '16 at 02:34 PM

I'm having a similar issue. I believe, by using the profiler, that the movement component is the issue. I'm not sure entirely how to address it.

avatar image Olverine May 02 '16 at 02:37 PM

Byt that's weird because in another project, I made AI characters that use the character class as parent and I could spawn hundreds of those.

avatar image Mesothere May 02 '16 at 02:39 PM

It's possible to have a very large number. However, for me, they only begin lagging when movement is requested - pathfinding or otherwise.

avatar image ColdSteel48 Apr 03 '17 at 09:19 PM

Have you found a way guys ? I am struggling with the same problem and I see that I am limited to ~ 40 characters right now and yes movement is the problem that takes the whole CPU time.

avatar image Starkium Sep 11 '17 at 03:30 AM

I am also trying to solve this. I have very simple zombies using move to player location. Is there a more cost effective way of doing this?

avatar image ColdSteel48 Sep 11 '17 at 07:02 AM

Yeah, I solved this, but you will have to get your hands dirty woth c++ for it to work I'm having around 200-250 characters now. I had to subclass CharacterMovementComponent and then apply Occlusion Culling to it's movement Ticks.

In General Indevided Characters in to Several Groups (so they're movement components won't tick togethere once they are not visible). In character Tick I querrt if they are visible on the screen - if yes then I let it's movement component to tick normaly, if not I stalling the CharactersMovementComponent Tick (while still calculating the right delta time) So in case that character is not Visible on the screen it will tick once in a while nit woth a proper DeltaTime - so it won't kill the movement accuracy and tine.

avatar image Starkium Sep 11 '17 at 09:31 AM

Not afraid to get my hands dirty. Any chance you could post some scree Caps or something. I'm haven't done any c++ in ue4 yet. I've done some outside though, so I could probably find my way around looking at it.

I'm working with wave based zombie ai for a VR game on a procedurally generated map made with dungeon architect. My nsv mesh is built on runtime. Not sure if any of that changes the usefulness of the advice at all.

avatar image ColdSteel48 Sep 11 '17 at 09:49 AM

I will post some code later on today. Well in General I'm also playing with RVO (toggling on/off) My nav mesh also rebuilds in runtime (I am using distructible environment)

Oh one last thing - I am also not using any collision spheres or something like that on a characters all the AI detections happens on a separate thread.

avatar image Starkium Sep 11 '17 at 09:57 AM

There are hitboxes on mine so they can ragdoll and also to determine how many points to award per body part shot. Limb, body, head, etc.

avatar image ColdSteel48 Sep 11 '17 at 10:00 AM

Well That can slow down your character as well, I suggest to dump the hit boxes and to work directly withba mesh bones, it will require some more work to map all the bones to the points - bit shall increase your movement performance .

avatar image Starkium Sep 11 '17 at 10:02 AM

I had suspicions of this. The character is a lightly modified version of the zombie from weapon master VR. I'll let him know about it too.

avatar image ColdSteel48 Sep 11 '17 at 10:03 AM

But wait with that, I will post some code snippets when ai will be back at home, try to implement it, and measure the performance maybe it will already satisfy your needs. (Since you didn't say how much characters you want to have on the screen).

avatar image Starkium Sep 11 '17 at 10:07 AM

At least 100 zombies at a minimum 90fps in an procedural open world with physics

avatar image ColdSteel48 Sep 11 '17 at 02:18 PM

Ok, so here you go:

You have to create your own CharacterMovementComponent: And add to it's header:

 class YOUR_GAME_NAME_API UCM: public UCharacterMovementComponent
     virtual void InitializeComponent() override;
         //Useful to make sure that your characters are using the correct Component.
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = StubCheck)
     bool m_dummyToMakeSure; 
     virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
     float m_DeltaTime;
     int m_nTicksCount;
     int    m_nTickGroup;
     bool m_SkipFloorChecks;

In the CPP

 void UCM::InitializeComponent()
     m_nTickGroup = FMath::RandRange(3, 4);
     m_DeltaTime = 0.0f;
     m_SkipFloorChecks = FMath::RandBool();
     m_nTicksCount = 0;
 void UCM::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
        m_DeltaTime += DeltaTime;
     if (!CharacterOwner->GetMesh()->bRecentlyRendered)
         if (++ m_nTicksCount % m_nTickGroup == 0)
             m_nTicksCount = 0;
             DeltaTime = m_DeltaTime;
     m_DeltaTime = 0.0f;
     //Call Default CharacterMovementComponent
     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

This code snippet will cull of some of the Movement Component overhead for an invisible Characters. Theoretically it should increase the number of Characters (that are off-screen) twice.

Please refer to this Wiki Page: on how to create a custom CharacterMovementComponent https://wiki.unrealengine.com/Custom_Character_Movement_Component

avatar image Starkium Mar 11 '19 at 01:28 PM

So I finally came back to this after a long ass time and I'm at a point where I actually understand everything you said LOL.

Still working on this same game, but now my concern about this tick groups technique is how does this work in multiplayer if the players are all on different sides of the map? This is only culling the rendering of the AI and not the actual movement of them correct?

avatar image ColdSteel48 Mar 11 '19 at 03:39 PM

Yes, tick is not affected by rendering. But the movement is affected by the tick-so the invisible bots will tick less but with greater delta time - it may make them to appear jagged.

But honestly, after all I just happened to reimplement everything, from NavMesh to CMC to have really decemt performance (without tick groups).

Here is a preview video lin: https://drive.google.com/file/d/1x4MPTSwyEtNeSRd1YHjr4nzOG41cp5Sc/view?usp=drivesdk

avatar image Starkium Mar 15 '19 at 12:23 PM

I'm probably going to make a simplified version of cmc and move off of behavior trees as much as possible in favor of Utility AI as suggested by Tom Looman. Going to also see if I can whip up some sort of instancing for the skeletal meshes as well as all the other weird ideas I've got floating around in my head. I was looking at the world war z game and I thought well if they can make huge mobs I can do it too!

avatar image Starkium Mar 15 '19 at 12:36 PM

also ( this is a clean project for working on AI ) but I get 110-120 fps with the AI idle and when they're all moving I get about 60 fps

alt text alt text

100ai-idle.png (2.8 MB)
100ai-moving.png (1.6 MB)
avatar image ColdSteel48 Mar 15 '19 at 02:14 PM

Sadly I don't get 120 FPS with non moving AI my SkeletalMeshes takes too long to render :( But movement wise can go up to 1000 AI with collision avoidance (in multithreaded case) and around 250 single threaded.

It still has a room for further optimization - but I just don't need - since I need only around 100-150 AI

avatar image Starkium Sep 11 '17 at 07:56 PM

alt text

This is pre your fix. I get about 40 fps here with 80 ai. Gunna put in your fix and see what happens

avatar image ColdSteel48 Sep 11 '17 at 08:15 PM

My Optimization texhnique as is seems not to help you since it delas with the Zombies that are not rendered to screen, in your Screen shot I understand that you can see all of them - I would suggest to alter the trick a bit: I would still use the whole part of ocluded optimization, but I would add a distance sorting as well for instance I would tick Zombies in 2-3 groups 1 tick function for a close zombies and 2 more for a distant zombies while those who are pretty close should get every tick the distant zombies can skip ticks as well lets say you will devide them in 2 groups and tick group 1 on every even tick and group 2 on each odd tick...

In best case you get twice performance on an average case you will get 1/3 performance improve... Picking a good distances treshholds will result for a human eye as a perfect movement even though you are skipping some ticks.

But 80 ai to 40 fps I have suspicions that you are failing at something else as well. I would assume these hitboxes are a pitfall - but you shall measure the performance for a bottle necks first.

This trick lets call it a Tick span - won't jump your FPS from 40 to 90 It may be beneficial with the addition Indeseibed here to get around 60fps...

Then go ahead and measure the other bottlenecks and try to optimize them 1by1

avatar image ColdSteel48 Sep 11 '17 at 08:17 PM

I will just add that I suppose that the screen shot is not an actual game play... Maybe if you post a screen shot from an actual gameplay I would assist more.

avatar image Starkium Sep 11 '17 at 08:29 PM

Hard to say what that would be like because I haven't figured out the best way to spawn them on the map yet. Thinking random chance of a spawn point on a tile. I can drop a bunch of zombies in the game and show you what that might look like in view

avatar image ColdSteel48 Sep 11 '17 at 08:34 PM

Okay then after implementing my spanning trick Just alter the spawns to be not in the same point Make 3 regions for each wave to spawn at

1/3 Zombies Close sonthey will get every tick other 2/3 on a distant enough points tomapplyna distance optimization trick.

In this case Assuming you don't have other bottle necks you might be able to reach 60-70 FPS.

The key is to cull the process - ot to process all of them in 1 frame - but process closest in 1 frame and span other accross multiple frames to cull of CPU bottle neck.

Also take a look of movement component - should your zombies ever fall somewhere ? if not - then tell MovementComponent not to check floor... etc etc...

avatar image ColdSteel48 Sep 11 '17 at 08:38 PM

I think that the most useful part for me was dropping BehaviourTrees and tranferring the most heavy parts of AI to a separate thread this alone allowed me to have ~ 100 AI with 120 FPS.

avatar image ColdSteel48 Sep 11 '17 at 08:40 PM

If you want you can take a look at my WIP game where I used it.

Run accross the map spawn as much AI as you can (by just running around the map , avoid werewolfs they are too strong) and look at the performance vs quality


avatar image Starkium Sep 11 '17 at 09:52 PM

alt text

80 ai with best and worse scenarios on screen, captured in game from the htc vive. Still don't have your fix in yet. Wanted to show what I have going on. This was still in the editor technically, it wasn't launched as a standalone game.

A separate thread for ai in general should always be a thing in my opinion.

80-ai.png (608.7 kB)
avatar image ColdSteel48 Sep 11 '17 at 09:59 PM

Good Luck Implementing! Making AI on a separate thread is a huge work to do. Go for it!

avatar image Starkium Sep 11 '17 at 10:15 PM

Daunting task for a noob. Also I played your game example and I get 90-120 fps with 20 or so ai on screen

I get ball park 90 fps with 20 zombies on my screen. Whats funny is that when I run it outside of vr mode, I get like 300 fps

avatar image ColdSteel48 Sep 11 '17 at 10:26 PM

My game is not for VR - and yes I have 300+ FPS Then I suppose CharacterMovementComponent is not your bottleneck.

Please post your profiling results

avatar image ColdSteel48 Sep 11 '17 at 10:36 PM

TBH didnt even know it can run in VR

avatar image Starkium Sep 11 '17 at 10:37 PM

sorry i meant my game outside of vr mode

kind of new to profiling. what should I be testing

avatar image ColdSteel48 Sep 11 '17 at 10:40 PM

90-120 FPS in my game ? Hmm what is your hardware ?

Profiling start from posting:

in console: stat.unit stat Unit or something like that look here


avatar image ColdSteel48 Sep 11 '17 at 10:45 PM

I get such FPS on intel hd on I-3 CPU which I consider as a great performance :-)

avatar image Starkium Sep 11 '17 at 10:49 PM


16 gb ddr3 1600mhz

500 gb ssd

gtx 980ti classified

profiling now

avatar image ColdSteel48 Sep 11 '17 at 10:51 PM

Your hardware is close to my, you should have around 270-300 FPS... Unless you are not on 4K display bit then again it would be a GPU bottleneck.

avatar image Starkium Sep 11 '17 at 11:01 PM

I have 3 screens, my vive, and a chromecast. then theres plenty of chrome tabs and what not. I've looked and removing all those things doesn't change anything.

I can see the profiler on screen but I can't get it to log anywhere. what am I doing wrong here?

avatar image ColdSteel48 Sep 11 '17 at 11:05 PM

I don't know, post a screen shot :)

avatar image Starkium Sep 11 '17 at 11:14 PM

oh wait I got it. needed stat start file

Stat Dump

avatar image ColdSteel48 Sep 11 '17 at 11:19 PM

I don't know how to open this, just post a screen shot

avatar image Starkium Sep 11 '17 at 11:19 PM

you open your profiler and load that file to see what was going on

I'll take a screenshot too

avatar image Starkium Sep 11 '17 at 11:25 PM

alt text

stat-raw.png (846.5 kB)
avatar image ColdSteel48 Sep 11 '17 at 11:27 PM

Your CPU is okay, the draw is very HUGE imo, seems like you have too many transparent objects on the scene.

You can check it by hitting F5 while in PIE

avatar image Starkium Sep 11 '17 at 11:31 PM

in editor is kinda hard to see anything because the pawn won't move without the vr headset. here is f5 from vrpreview

alt text

f5.png (174.6 kB)
avatar image ColdSteel48 Sep 11 '17 at 11:34 PM

Your Zombies has some transparency ? Shader complexity shows a lot of pixel overdraws at the right half of the screen where the Zombies are (Note the White color - it is very bad )

avatar image Starkium Sep 11 '17 at 11:34 PM

this is at the zombies feet because the headset starts on the ground from pie and I can't move the headset while in editor

alt text

pie.png (305.1 kB)
avatar image ColdSteel48 Sep 11 '17 at 11:37 PM

You probably shall start from reading this post


avatar image ColdSteel48 Sep 11 '17 at 11:36 PM

You will want to reduces transparent/translucient objects to a minimum while working with VR.

avatar image Starkium Sep 11 '17 at 11:39 PM

I have none that I'm aware of. It's all low poly and flat textures. no shadows either

avatar image ColdSteel48 Sep 11 '17 at 11:40 PM

Can you post zombie's material ?

avatar image Starkium Sep 11 '17 at 11:46 PM

alt text

They should all look like this. I'm using assets from synty studios

mat-example.png (377.1 kB)
avatar image ColdSteel48 Sep 11 '17 at 11:49 PM

Well, I don't have any VR experience to help you with this. Anyway your problem is not an AI itself, but the GPU you should look for optimizing your GPU draw calls.

avatar image ColdSteel48 Sep 11 '17 at 11:49 PM

Not sure though why your material has so much instructions :-?

avatar image Starkium Sep 11 '17 at 11:53 PM

are you sure it's the zombie?

avatar image ColdSteel48 Sep 11 '17 at 11:58 PM

Hard to say, but it looks so. Look at the shader complexity so much instructions - try to use another material - something with just a flat green color (just for the test) and see if it helps

avatar image Starkium Sep 12 '17 at 12:07 AM

I'll do that. Check it out though. I made an empty level with 60 ai spawners and a nnav mesh and a plane. Massive dips.alt text

empty.png (678.8 kB)
avatar image Starkium Sep 12 '17 at 12:09 AM

my zombie ai does a random int before it spawns to pick a a mesh from an array. I doubt it's loading all meshes for each zombie because they'd show up. When I'm placing the actor on the map you can see it cycling the meshes till i place it and then it stays with the placed mesh. I had these issues before I added that feature, which was today btw.

avatar image Starkium Sep 12 '17 at 12:11 AM

alt text

I feel like it's not the material

avatar image Starkium Sep 12 '17 at 12:12 AM

each character has around only 312 triangles too so that's not it

avatar image ColdSteel48 Sep 12 '17 at 12:16 AM

Don't show me the values form the editor - try to make them in a standalone game - in editor you can not know what is the bottle neck.

In the graph you showed it is till the GPU Issue but not in Draw calls right now.

I suggest you to ask a new question here in answer hub.

With your profiler results.

avatar image Starkium Sep 12 '17 at 12:56 AM

ok, thanks for your help

avatar image Starkium Sep 12 '17 at 01:12 AM
avatar image ColdSteel48 Sep 12 '17 at 01:17 AM

Just out of curiosity: what if you will disable all the AI on the zombies will they still kill your fps ?

avatar image Starkium Sep 12 '17 at 02:24 AM

so just the mesh an an animation?

avatar image Starkium Sep 12 '17 at 03:09 AM

No mesh, no animation, nothing to pull in any visual data from and have 60 empty characters on screen.

The result is 50 fps at 15-17ms on the gpu. NOW I'M EXTRA CONFUSED

avatar image ColdSteel48 Sep 12 '17 at 11:22 AM

Zombie - just a mesh and animation.

Without AI controller I meant

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Consider moving your AI from Blueprints to a Behaviour Tree based solution, even if it's just using Move To. iirc, the behaviour tree Move To node is capable of running the nav query over multiple ticks so the performance impact won't be as drastic.

On a side note, if @MieszkoZ still hangs out in the Answer Hub he should have some much more detailed advice as to how best to optimise that sort of thing.

more ▼

answered Sep 11 '17 at 04:21 AM

avatar image

43 6 8 13

avatar image Starkium Sep 11 '17 at 09:29 AM

Mine is already in a behavior tree.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question