TheGameCreators / GameGuruRepo

The GameGuru Repository For Community Collaboration
http://www.game-guru.com
137 stars 56 forks source link

Support for Hundreds/Thousands of Characters on screen at once #4901

Open extremestrategy opened 1 year ago

extremestrategy commented 1 year ago

So I was using the Cloning behavior to spawn massive amounts of NPC's, and upon racking the number up to 100K NPC's, even with Rabbits i was getting about 1-2 FPS, and with something like 1K soldiers Max will crash as they all try and attack the player, now I get 100K NPC's is a bit much, but can the optimization be boosted to handle at least 1K at minimum, 10K would be much more appreciated.

davetgc commented 1 year ago

10k is far too many, most games won't have more than 100 active at any one time, and often only 10-20.

Games use careful planning and design to give the impression of hoards of enemies, rather than actually swamping the PC's resources.

Could you however please post your system specs, so we can look at the crash.

extremestrategy commented 1 year ago

Sure thing.

Processor 12th Gen Intel(R) Core(TM) i9-12900K 3.20 GHz Installed RAM 32.0 GB (31.7 GB usable) System type 64-bit operating system, x64-based processor Graphics Card Nivida GForce RTX 3060 Available Storage 569GB

davetgc commented 1 year ago

Thanks, I'll flag this as a crash, but in all honesty, I can't see why anyone would need even 1k characters active at once. I suspect you're simply running out of system resources.

As a guide, even 50 characters, active at once, would be a serious challenge to most systems Users are much better using clever level design to create the impression of endless hoards.

LeeBamberTGC commented 1 year ago

@extremestrategy Can you send me a video clip of a modern game that puts 10K characters on the screen at once, thanks :)

Lemuripest93 commented 1 year ago

I think the most obvious candidate for most characters on screen at once in a modern game would be 'UEBS 2' [AKA Ultimate Epic Battle Simulator 2] where not only can you have 10 thousand characters at once, you can have upwards of millions.

Here's a video of someone fighting 30K characters in first person: https://www.youtube.com/watch?v=lUqESjZ9loE

UEBS is an outlier though, this is not common for obvious reasons, lol.

LeeBamberTGC commented 1 year ago

@Lemuripest93 That's a great video link, never seen that before: image image

Lemuripest93 commented 1 year ago

There's also a series of games called 'Mount & Blade' that goes beyond just having impressive large scale battles that does something similar, where those game has RPG mechanics like making your own character, buying up weapons, armor, horses, food and etc and has some strategy mechanics as well, where you try and hire mercenaries until you can amass a massive army and take on other kingdoms and their armies.

Here's a video from that same YouTube channel showing a battle in the most recent entry in the series: https://www.youtube.com/watch?v=zUFx6xIn9bg

Could be fascinating to see if this affects MAX's development down the line, but personally i'm more interested in making highly detailed maps with a small to medium character count myself, lol

extremestrategy commented 1 year ago

@LeeBamberTGC Just look at the Total War series https://www.youtube.com/watch?v=_y9BmvJ37Ns they run even higher then 10K, sometimes all the way up to 20-30K depending on settings, number of armies, etc.

TenebreGaming commented 1 year ago

Game engines use many obfuscation and LOD methods in order to produce these effects. But the important thing is that the engine is usually tweeked internally if not designed entirely around the game. One of the methods used to do this is clustering, where you might have 10, 20, or even 100 low-poly entities combined into a single actor. Another method uses sprites to do a similar thing using impostor systems. It's extremely difficult to make such thing generic.

fearlesswee commented 1 year ago

If you want to see an example of an FPS series that does this (as MAX is more oriented towards making FPS games), the Serious Sam franchise comes to mind, particularly the 4th game, which features something called the "legion system."

image

The way this system works under-the-hood is that it basically "bakes" a sprite sheet of the given enemy model, from various angles and in various poses. When a given NPC "agent" is far away from the player, they get rendered as a sprite (ala DOOM 1993) with VERY simple approximated physics, and VERY simple AI (being little more than "walk forward). When a given agent is close enough to a player, the sprite fades out and is replaced by a proper 3D model of the enemy type, and their usual AI routines activate.

image

Here's a gameplay snippet of the system in-action.

There's also a bunch of other under-the-hood tricks to support high enemy counts outside of the legion system, including batching, time-slicing, and animation throttling. (Some of which I already suggested.)

3675 #3674

LeeBamberTGC commented 1 year ago

Thanks for all the ideas and suggestions. I think this is actually in two parts, the first is simply to render lots of a same instance in the distance using a smart technique, not just characters. Even the current Wicked Engine we are using has this imposter system available, and will probably be the approach used.

The second part can be summed up as a way to manage swarms or large groups of units, not individual units running their own script. Running 30,000 scripts per frame would not be wise :) This second part can be looked at once more critical issues are behind us as I suspect most creators are not thinking of recreating Ultimate Epic Battle Simulator any time soon.

extremestrategy commented 1 year ago

Thank you, that seems fair to me, I can understand not wanting to run 30K scripts at once lol, and I look forward to seeing your enhancements.

fearlesswee commented 1 year ago

Reposting this from the Discord:

Did my own little test by manually placing down an insane number of zombies. (Pardon the over-saturated visuals; it's a reshade preset I was toying with for my actual project which is a lot more dark and moody so it doesn't look great in this test environment lol)

Ran shockingly well, keeping around 40 FPS minimum with the ridiculous amount of zombies, with the only notable issues being that it some zombies would die standing up, some zombies near the back of the group didn't seem to respond to the player's presence (maybe the zombies in front were blocking their line of sight? Could be solved with a custom behavior that ignores line-of-sight.) and the engine didn't seem to like shooting a gun into a big group (caused a bit of additional slowdown)

But given this is FAR from intended behavior, and there's yet to be any major optimization passes done here, this is VERY impressive. I must assume then that MAX probably gotten some minor improvements to AI/Character under the hood since my last test, which, granted was like a year or two ago lol MAX_Zombie_Horde

MAX already surprisingly handles large groups of enemies quite well, so I can imagine with just a few key optimizations, primarily time-slicing, batch-processing, animation throttling, and a custom behavior script especially designed to run large groups of enemies at a performant level, hundreds of characters in MAX is definitely feasible. A more nuanced system and special focus on optimization in this area (such as rendering distant enemies as sprites/imposters and limiting their physics and AI heavily) would be necessary for thousands, but I think this is certainly doable.

LeeBamberTGC commented 1 year ago

Thanks for the repost, and thanks for running the test, a good early starting point before we switch on hoard mode :)