best method for optimize many NPC movement?

For context, I’m trying to get as many NPCs as possible. The target is 200 NPCs in front of the player with 60 fps. I know the main bottleneck is the skeletal mesh and animation blueprint and have a solution for that (so don’t worry about GPUs). For this post I just want to focus on optimizing the pathfinding logic.

The current method is to connect the “ai move to” node to the event tick and set the class’s “Tick Interval (secs)” to 0.5s. Thus every 0.5s will update the current location that the player is at as the player is moving alot.

Is this a good, performant method or is there a better method?

Like is there an even more simplified method, multithreading, or some how dumping this on the gpu, or some other clever method?

Try changing this:

1 Like

What is this and how does it impreove performance?

This is something like Tick Interval, but for movement component. You can find it inside your AI, it’s in Movement Component.

1 Like

The way to optimize the pathfinding is to not do it so often.

Do it when the NPCs are away from the player and do it rarely - once every 5 sec. You need to get them to the same room or space as the player using PF. Nothing more.

Also you can group close by NPCs, choose a leader and path-find only for them assuming the other NPCs in the group will just follow.

Once close enough just move in a straight line to the player, eventually with some boid avoidance.

This will not solve mazes for you but will work in almost any environment. For 1000+ or very large spaces use flow maps.

If you want something “out of the box” you can check Detour Crowd Manager and their crowd avoidance here: Using Avoidance With the Navigation System in Unreal Engine | Unreal Engine 5.6 Documentation | Epic Developer Community

1 Like