Humanoid Optimisation and 500 NPCs

Background

For our upcoming series finale we wanted to do something big. With the help of @Z00LD and @ObliviousHD, we’ve created some monster morphs, corresponding animations and a hell load of NPCs.

First attempt

Our first attempt involved ~50 NPCs and was not quite what you could call the pinnacle of smoothness…
https://i.gyazo.com/91692e6db81b4c0dd2572b189aef13aa.mp4

Optimising the Humanoids

After a bit of looking about and seeing what other developers had done who successfully tackled large groups of humanoids, we applied the following edits:

  1. Transferred and handled everything on the client.
  2. Anchored the HumanoidRootPart of each NPCs and used TweenService to move the humanoids.
  3. Set every single HumanoidState to false.

Final result

My video recording software doesn’t do the scene full justice so if you have a spare second I’d highly recommend watching the complete version in-game: The Breach - Roblox

I may look at open-sourcing the place afterwards if that’s something anyone’s interested in playing around with. Hope you enjoy!

47 Likes

If you’re going to disable every feature of the Humanoid, just remove it. AFAIK it should increase performance, too. (I see this fact thrown around a lot with no evidence, but they’re probably right.)

7 Likes

Call LoadAnimation on an AnimationController

instead of

humanoid:LoadAnimation(animation)

do


AnimationController:LoadAnimation(animation)

AnimationControllers act as humanoids in the sense that you can load and play animations into them (given your model is properly rigged) but without all the unwanted calculations of a humanoid object. Search AnimationController in the advanced objects tab, then insert it into your character model!

This is how a lot of games handle Static (and sometimes moving) NPC’s.

Beware, AnimationControllers wont enable you to use clothing.

4 Likes

After replacing each Humanoid with an AnimationController I found the one with Humanoids to be faster than the one with AnimationControllers, which seems especially odd because of the points you mentioned.

Here’s the place with Humanoids:
https://www.roblox.com/games/3497425631/The-Breach

Here’s the place with CustomControllers:
https://www.roblox.com/games/3498599677/AnimationControllers

Both were tested under the same conditions on a 1 player server.

3 Likes

That’s really weird. Could we see your implementation? just a snippet of code works

Sure, I’ll dm you the files of both

In game it is very impressive, would it be worth flattening the terrain the monsters walk over because there is a ditch in the middle they levitate over.

Overall very well done!

1 Like

Really should push Roblox to optimize the humanoid code base. It seems like the bit of legacy code that is holding the platform back the most.

4 Likes

I’ve done something similar to this while testing some things out, which had led me to making a mini tower defense game that can hold up to 1000+ zombies

I lost the game file after cleaning up my computer storage

1 Like

Remember; if its a new project, upload a place file.

2 Likes