NPCs running slowly

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.

Thanks

3 Likes

Either one of my quick thoughts has it’s caveats:

  • Custom humanoid
  • Physics ownership but for humanoids; Humanoid ownership

I don’t think your bottleneck is memory, but rather raw processing speed.

1 Like

I’ll look into that :wink:

Already started working on a custom humanoid but decided to give up because it’s a lot of work and probably won’t do much.

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:

2 Likes

Hmm, forgot to do a search, my bad :wink:

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.

1 Like

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

2 Likes

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.

It’s not client-side lag, though. It’s the server that is having trouble. Unnecessary states are also disabled.

Im saying only spawn the humanoids into the server if a player is in the region.

2 Likes

My map isn’t big enough for that to be worthwhile RIP. It’s big, but it’s also open so NPCs need to be seen from a distance.

1 Like

Setting the physics ownership worked, if I have any further issues I’ll check out the solution with multiple scripts. Thanks :wink:

1 Like

Late reply, but try looking into disabling certain humanoid state types that you do not need. Things like climbing, swimming, and a few misc things should help with the issue. https://www.robloxdev.com/api-reference/function/Humanoid/SetStateEnabled

For a specific list I suggest disabling…

RunningNoPhysics
Climbing
Ragdoll
GettingUp
Flying
Seated
PlatformStanding
Swimming

3 Likes

Yeah I’ve already done that.

Could you try with 2K NPCs for me? :3
But first save the place, create a backup, create backup for that backup and do the same for the last backup :3

1 Like

Why would you have 2000 NPCs in a single place?

Curiosity(Absolutely not thinking about realistic spectator tech or total war series :3 )

1 Like

I’m sorry but what did you set the physics ownership to to fix this issue?

1 Like

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).

My Laptop Specs

Alienware 17 R5

OS: Windows 10 Pro


GPUs:

  • NVIDIA GeForce GTX 1080
  • Intel(R) UHD Graphics 630

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.

1 Like