So I’m making an RPG that will have hundreds of enemies in a single place. I’ve been using some basic R15 NPCs, but when there’s a lot of them, their running speed (from Humanoid:MoveTo()) slows down a lot:
In this video I have 340 NPCs. That would seem like a good amount to be accurate for the game at release. Server memory is only about 200 mb.
I’m unsure what to do – everything seems to be fine apart from their speed, and their WalkSpeed values haven’t changed.
I have noticed that when I have lots of NPCs the physics engine goes crazy. Lucky for you, this topic has been discussed pretty heavily recently. Here are two threads you may find interesting:
The solution of having a single script controlling a group of NPCs instead of a single script for all NPCs sounds interesting – I’ll look into that too.
This is almost certainly a server cpu bottleneck.
You can test this by printing out the step variable in heartbeat. The larger the number, tje longer each frame is taking to calculate on thw server.
You can definitely try grouping many npcs together, but another thing you might want to try is only loading a single hitbox on server for each npc, and loading all particles/visuals and character models on client ( fewer parts to worry about for physics, then)
EDIT: You can also ignore control for bots that arent close to a player - there is no point expending compute time if there is nobody nearby
I know there are a few tricks like, turning off the climbing state for all the humanoids. I would suggest you make a kind of streaming service for humanoids in your game, only spawning humanoids when players are nearby.
Can you tell us what did you set the physics ownership to, to fix this issue?
I’m having problems with running 225+ NPCs in Studio Accurate Play Solo
I get around 35 FPS with 13 HumanoidStates Disabled and 27 FPS without any HumanoidStates Disabled for 250 NPCs moving around without Animations played while also using CollisionGroups to disable collisions between all of the NPCs, however some NPCs will Teleport if I SetNetworkOwner to nil (Server).
Hi, terribly sorry for necrobumping, this is WAAY too long ago. I was wondering how you settled the physics ownership? I am also a person suffering with this problem.
Set the NPC’s HumanoidRootPart’s network owner to the player who they are following. I’m not sure if this actually works as I haven’t looked at this problem since making this topic lol.
However, setting network ownership like this may not be very secure as exploiters could control the position of NPCs freely.
Here are two alternatives:
Disable as many humanoid states and unnecessary collidable parts on the NPCs as you can (if you are not already). This may not fix your problem, but it might be good enough.
Custom NPC movement/animation/etc. controllers. These should end up being much more simple and do less work than humanoids (for example, an NPC could be represented as only a single collidable part on the server, and then the rest of its appearance including animations is applied client-side). I recommend that you write your own to get an understanding of what is happening.