Is it possible to manage 100 NPCs without causing too much strain on the server?

I’m beginning work on an NPC system. The tasks that the NPCs must accomplish are as follows:

  1. Spawn within a specified amount of studs of players at random
  2. Choose a random nearby goal position, travel there, and when reaching that goal choose another
  3. Engage in (Breath of the Wild-style) combat with players when within range, change targets based on damage dealt over a specified period of time
  4. Engage in combat with enemy NPCs

Since this is a multiplayer game, what I’m most concerned about is the server strain that an NPC system like this would cause. Calling :MoveTo(), using PathfindingService, handling combat, etc., seems like it’d cause a lot of stress. Very curious as to how games with sophisticated NPCs manage to function and the feasibility of a system like this.

create 1 loop for all the npcs, run each npc on their own thread so it’s not overkill

If you’re still not getting good enough performance, you can try using crazyman’s approach of only rendering those that are on-screen. Takes a bit more effort in terms of figuring out where they should be on the server and replicating but very performant:

3 Likes

Interesting, I’ll definitely keep this approach in mind if I need to render a substantial amount of NPCs at once. (Thanks for the video @Crazyman32) My main concern at the moment isn’t so much a drop in FPS because of too much geometry or moving parts, but instead an extreme amount of strain on the server that would cause high ping due to constant server load.

2 Likes

I run about 57 NPC in my KonoSuba game tests and I see 0 strain. Make sure you disable the humanoid states you aren’t using and you’ll get so much better literal performance.

Here’s an example of it in action: https://i.imgur.com/jYDKROO.webm

The states I disable are

humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false);
humanoid:SetStateEnabled(Enum.HumanoidStateType.Flying, false);
humanoid:SetStateEnabled(Enum.HumanoidStateType.StrafingNoPhysics, false);
3 Likes

Much appreciated, thanks. What exactly is the server doing for your NPCs?

That webm was from 3 years ago so I understand the framerate was pretty mediocore, but they did run smoothly in my game with a situation more realistic (more than just NPCs)

The server is simply telling them where to go, pathfinding (using the node system you can see in the screenshot above) w/ raycasting, and moving them.

1 Like

I would not manage them on the server, while they may not strain the server, it will make the client lag, instead I would make an invisible hitbox on the server, and on the client create npc’s with the linked hitbox, I would move the hitbox on the server and generated paths to new hitbox’s position on the client, doing this on the client will help you save a ton of performance by only rendering npc’s in the view of the camera.