Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

A game with 5000~10000 zombies is possible?

Discussion in 'Scripting' started by johjitest, Apr 3, 2022.

  1. johjitest

    johjitest

    Joined:
    Dec 4, 2020
    Posts:
    6
    Right now I can only put up to 300 zombies ( with primitive colliders, animator and scripts with minimal update() usage) and I also tried some basic tuning like implement LOD to reduce verts still I can only manage around 600 is giving me 25+ fps and is playable but I feel like I am missing something because there is now way I can only use 600 zombies in my game. Any suggestion is highly appreciated.
     

    Attached Files:

  2. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    Believe it or not it is possible but potentially difficult, you could make use of DOTs for example and research that to have those kinds of numbers. The problem is though you will always be limited in hardware when it comes to the amount of gameobjects you can render and calculate on a screen at once and that's something that isn't going to magically go away with multi-threading support.
     
    johjitest likes this.
  3. johjitest

    johjitest

    Joined:
    Dec 4, 2020
    Posts:
    6
    I can definitely agree on DOTs helping with pathfinding, but I still can't grasp the concept on how will it help the physics and camera rendering. Does learning DOTs need some degree on CS or will installing package and some tutorial will help me achieve my goal (I know it varies case by case but I still appreciate any headsup)?
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,355
    Use the profiler to find out what's slowing your project down. You mentioned trying LODS, but was the number of verts ever really a problem?
     
    johjitest likes this.
  5. johjitest

    johjitest

    Joined:
    Dec 4, 2020
    Posts:
    6
    @kdgalla
    TBH I took a guess and thought LOD will fix my problem (which kinda helped but not fix. Manage to double the amount of zombie by 2 since my LOD0 halves the facecount of each gameobjet) but it didn't. Right now my profiler tells me FixedUpdate, PrelateUpdate, Update and Camera eats up 50% of the performance which I thought is normal but base on your comment perhaps I might need to try some tuning on some other parts besides verts.
     
  6. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Possible? Yes. Easy? No.

    You simply cannot have that many dynamic objects using traditional Unity workflows (aka: each one has their own Update/FixedUpdate, Animator, etc) at acceptable performance levels.

    Like you found it's not the nuber of vertices which is the problem: it's going to be updating all those scripts and animators. The "traditional" approach only scales up to around a couple hundred objects at best, much less if they have any sort of complex behavior like firing raycasts and reacting to trigger events and whatnot.

    ECS is designed for this kind of scenario, but it's still in preview and doesn't even officially supports Unity 2021 yet. However, you can use the same principles combined with Jobs and Burst to speed up GameObjects: have arrays of structs with the state of each zombie, loop over that data to update it, then apply the result position/rotation/animation frame to the target game objects. You can even modify Transforms in multithreaded jobs using TransformAccessArray.

    Also forget about using Animator, it won't cut for such large number of objects. When you get in the thousands even the faster legacy Animation component might be insufficient. You may need to employ a different animation strategy for zombies at different distances from the camera, assuming this is a 1st or 3rd person game: if it's top down and you can see all zombies from the same distance you need a simpler animation system for all zombies. Something that works is using shader-based vertex animation, where you bake the animation data in textures then access it from the vertex shader.

    When you reach thousands of objects, the number of draw calls also becomes an issue. Being able to use GPU instancing becomes important, so you need to do things like using only a single material for all zombies and shader-based animation, and use per-instance data to vary the visuals/animation state of each zombie.
     
    WalnutBat and johjitest like this.
  7. johjitest

    johjitest

    Joined:
    Dec 4, 2020
    Posts:
    6
    @Neto_Kokku

    Thanks for the detailed explanation !
    I think my unity journey is about to get brutal from here (this is my first unity project).
    Knowing the existence of DOTS/ECS gave me hope about this project,
    I thought I needed to give up unity and write my own rendering program using c++ or some low-level language ( I am from CS background but not competitive).
    I just need to clarify some things if its okay...
    First thing I need to get my hands on is DOTS/ECS in order to deal with unity's single-threadedness.
    Second one is to deal with animation which is a problem if I continue using unity's animator/animation component ( any heads up or thing/library to look for/learn from?)
    Third one is draw calls(?) I don't know a single thing about this one but it seems interesting.
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    Your writing makes it feel like you're winding up for this massive BLAST of work that's gonna be all definitive and perfect on the first pass and when all the smoke settles you'll have this mega-thousand zombie game that is more awesome than anything ever created before.

    That is NOT how software development works.

    In software engineering you iterate one step at a time.


    You start with one zombie. You iterate until that zombie does everything you need.

    Periodically you might scale up to 100 or 1000 zombies to get a feel for what is going on performance-wise.

    As you work, each step of the way you need to ask yourself "Can I?" just like this guy:

    Imphenzia: How Did I Learn To Make Games:

     
    johjitest likes this.
  9. johjitest

    johjitest

    Joined:
    Dec 4, 2020
    Posts:
    6
    @Kurt-Dekker

    Thanks ! You are right ! I am getting stucked in a problem that I should be doing later on the process.
    I did spend the whole day for this and next time I have time for this project I think I will continue implementing
    more stuff that is really required by my game.
     
    Kurt-Dekker likes this.
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,521
    I would add that if this is part of some curiosity thing then you can still satisfy that urge and learn a lot of stuff at the same time by ignoring what these things are (or could be later) and doing something like 5000 to 100,000 points in space all swarming together. You'll learn a lot simply doing that and just how powerful even a cheap CPU can be if you lay out the data for it correctly so it can linearly blast through it. Ignore the zombies, the blood, the complex interaction, the environment etc.

    In my years, I've not so much learned how to do stuff but more of how NOT to do stuff. Navigating those pitfalls is called experience. This is why it's still challenging to solve problems, the problems are still there but you can avoid a lot of the pitfalls ... most of the time. ;)

    This could even be a weekend challenge.
     
    johjitest, hippocoder and Kurt-Dekker like this.
  11. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,002
    Even with DOTS, animator is too expensive to be able to run 10k of them.
     
  12. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    Not only learning what not to do, but also learning how not to do stuff while fooling the user into thinking there's a lot of stuff happening.

    All games create an illusion of a lot more going on in the world than actually is going on.

    In GTA there isn't a huge city of people and vehicles all driving around and doing stuff. That doesn't exist.

    There's a tiny shell of stuff going on around you, and an even tinier shell of stuff being rendered in your field of view.

    Everything else just doesn't exist. Not only that, it wouldn't even be useful if it did exist. Why would the user care?

    Same goes with a zombie game like Dead Rising. The shopping mall itself isn't even loaded fully, and all the millions of zombies all over the place certainly do not exist. Nearby zombies exist but beyond a distance they're probably imposters, just cards placeholding for real zombies. And beyond that, just a void.
     
    MelvMay, beinzheans and johjitest like this.
  13. Thethispointer

    Thethispointer

    Joined:
    Feb 11, 2018
    Posts:
    105
    Isn't it called Entity Component System or something... I just looked it up and yes.

    This is how to add thousands of objects into a scene.

    https://learn.unity.com/tutorial/entity-component-system#5c7f8528edbc2a002053b67b

    Also look up object pooling, some tricks in that frame of thinking may help make it look like more zombies than you actually have active at one time.

    Also, async scene loading and unloading can bring other "levels" into play and connect the ground surfaces without seam.