Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Thousand units RTS

Discussion in 'Works In Progress' started by TwiiK, Feb 4, 2017.

  1. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,614

    http://twiik.net/projects/thousand-units

    After coming across a thread on Reddit I was inspired to try and make a game with 1000 units in Unity to get a feel for what it takes to make an somewhat optimized game in Unity. Usually optimization is something I've never had to care about when making games so this will hopefully be a fun challenge.

    My first approach made this seem impossible because I tried what I thought was the simplest, most optimized thing I could do and that was just to have 1000 game objects which I moved in Update(), but apparently having 1000 Update() loops is the opposite of optimized. I later learned that the built-in navigation system is very optimized and not only does it handle movement much better than my naive approach, but suddenly I had actual pathfinding and object avoidance as well, things I thought would be extremely hard to implement.

    I then wanted the units to fire missiles at each other, but 1000 rigidbody missiles at once caused a lot of issues. I thought I could optimize this by using particles instead, but apparently when you want particles to be able to collide with 1000 objects they are much less performant than the built-in physics. I also tried a raytrace approach I've used in a lot of my games, but that was also less performant than the built-in physics so I reverted to just using rigidbodies, I just limited the number of missiles for the time being.

    I then added some particle effects, trails, sounds, a terrain and a simple camera controller and suddenly things started to look really cool. The look I'm going for is inspired by Homeworld: Deserts of Kharak because I think that game looks really cool even though it doesn't have that much else going for it. And I just love simulating projectiles. I then implemented some object pooling which I've never used in Unity before and so far things are looking pretty good.

    The most important thing for me with this project, as with any of my projects, is that every single thing should be simulated and consistent, I don't want any smoke and mirrors or tricks. I know this is kind of the opposite approach of almost everyone who develops games, but I've never had to actually release a game so I can do whatever I want. :) I know released games with thousands of units use all kinds of tricks to only simulate small subsets of units at a time etc. etc. and I don't want any of that, I want each unit in my game to behave as if it was the only unit in my game, but we'll see how realistic that actually is. I've already had to limit the number of simultaneous missiles by a lot, but that was also partly because 1000 missiles didn't look or sound very good. :)

    At the moment I'm not sure where or how far I'll take this project. Currently it's just an observable demo, I'm not sure if I want to make it into a game you can actually control or not. I know I want to improve the graphics quite a bit and I'll focus on trying to squeeze out additional performance while at the same time adding more features, I guess.

    You can download the project or standalone versions for Windows or Mac from the above link. I reserve the right to stop updating the downloadable project at any point if I realize I want to turn this into a game or if I want to use commercial assets or for whatever other reason, but at the moment I'll update it whenever I update the standalone builds.
     
    jason-fisher likes this.
  2. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    3,576
    This is very interesting to me, I'll take a closer look at the project later. Did you (or anyone else) ever do a performance comparison between Unity's nav system and AStarPP?
     
  3. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,614
    I've not done any comparisons between different systems so far and at the moment the navigation is by far the biggest performance hit in the project so I'm sure some optimization could be made either with the built-in solution or with a different solution.

    This project is only about a dozen or so hours old at this point and basically my first stab at this.
     
    Martin_H likes this.
  4. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    425
    2 years ago on a simple ipad air, it was possible to play with 1800 units on Unity4.
    On my computer I could easily reach 10000units.

     
  5. Ronald_McScotland

    Ronald_McScotland

    Joined:
    Jul 30, 2014
    Posts:
    174
    Looking forward to seeing how far you can push this. You'll probably find as I have that putting skinned meshes on large numbers of characters is the big performance killer.
     
  6. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    425
    I just tried with Unity5.5 , I can have now 4000 cubes units.
    I use Unity Navmesh for movement, and a Thread to calculate collision and distance between each object.
     
  7. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,614
    Yeah, already noticed that in another project I'm working on with only a few dozen characters. There is something called GPU skinning in Unity, but I haven't been able to get that to work, the entire performance hit is still on the cpu for me.

    Well, you had 5-30fps or something in those videos you showed. That's already far beyond the point where I would have pulled the plug. :p But either way if you try to move 1000 units at once with the navigation system it seems they are handled in batches and you can see them move in groups, so I think it doesn't matter all that much how many units you have if you're only dealing with the navigation system, but it's all the other components and gameplay mechanics you may want in your game which will kill your performance. For example I tried playing 1000 sound effects at once and that froze Unity. :p And if you have 1000 units it is expected that they can all perform some type of action in your game. At the moment I've limited the number of units who can shoot at once to 20 on either team, that would feel quite S***ty if this was an actual game, lol.

    I may play around with some other navigation options as well if I can find some free alternatives, I'm not going to spend money on simple prototypes.
     
    theANMATOR2b and Martin_H like this.
  8. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    425
    You can't create a group and use navmesh if your terrain is not flat and if you have some objects to avoid.
    I have no problem in my Orcwar RTS game to manage 200 units with skinned mesh and sound on Mobile



    Instead of create a audiosource for each units, create only a audiosource for all units, and limit to 5 sounds the maximum of sounds played in the same time