• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Will Large Quantity Of Units Cause Lag?

Status
Not open for further replies.
I place about hundreds of units on my map, I've seen a topic which say there would be lag if I put too many units. So I think of a solution that I'll hide all unit at map initialization, then unhide about 50-70 units when players enter a specific region. I tested it, and it didn't cause lag to me, but I wonder if the others have the same result, because my CPU is a little... strong.

What is the best way to make a crowd, each unit in which would do different work? I mean, I'm making a town and I want every unit in my town can do various actions like work, wander around, attack, patrol,... not just standing there like a statue.
 
I place about hundreds of units on my map, I've seen a topic which say there would be lag if I put too many units. So I think of a solution that I'll hide all unit at map initialization, then unhide about 50-70 units when players enter a specific region. I tested it, and it didn't cause lag to me, but I wonder if the others have the same result, because my CPU is a little... strong.
well, if the map is multiplayer and you hide units and show them under certain condition (assuming only player that enter the condition, in this case, the region will see the units) it will desync.
however, it shouldn't lag since only a portion of unit is unhidden.

What is the best way to make a crowd, each unit in which would do different work? I mean, I'm making a town and I want every unit in my town can do various actions like work, wander around, attack, patrol,... not just standing there like a statue.
Use Triggers for each unit, if it's a pack of unit, use unit groups and order them to do bla bla
 
well, if the map is multiplayer and you hide units and show them under certain condition (assuming only player that enter the condition, in this case, the region will see the units) it will desync.
however, it shouldn't lag since only a portion of unit is unhidden.

u can show and hide units for a specific player without a desync.
u cant create units in get local player block.

Use Triggers for each unit, if it's a pack of unit, use unit groups and order them to do bla bla

if u r worried about creating lag when creating 100 units at a time instead create 1 unit every .01 second. this will take 1 second to create 100 units and it should not lag at all.
 
Level 16
Joined
May 2, 2011
Messages
1,351
I think it might cause some sort of lag
what I have tried is I had some battle between 5 players or something, and there are many necromancers and they raiised many skeleton warriors, and I used starfall ability, ultimate of priestess of the moon, and it got a little bit messy, not that huge of lag, but not as smooth as it was before that
 
It depends. Having a bunch of units will end up adding some performance degradation but the biggest impact on frame rate is what is currently rendered on the screen. Hiding them may help a little, but you can get even more significant results by altering the camera options. However, if you do this locally then it can be prone to desyncs. It doesn't desync immediately, but if some other player interacts with a unit that is hidden for another, e.g. select/move, it will desync.

First, if you have an RPG camera or a first person camera, the main thing you want to pay attention to is Far-Z. Reducing this will significantly affect the performance. If you have a bird's eye view, then you can try altering the field of view to reduce what is seen on the screen, or zoom in a bit. I recommend that you make a dialog option that will alter the camera values as necessary (e.g. Quality Adjusting, you can choose "Low", "Medium", or "High" and it will alter the camera values accordingly). This way, those with higher end computers don't have to suffer limited perspectives and those with lower end computers can actually play your map.

As for the crowd thing, you should trigger it for each unit. Abilities like wander, and randomizing it, can lead to odd things. For example, some unit might run into a wall or the units might end up doing something nonsensical. If you have proper pathing and limit the units, then giving them the ability "Wander" may work, but use it with discretion.

I personally would make a system to define pathways that units can walk on. If you want a random sort of effect, you can make road branches and randomize which path the unit takes. If you have a bunch of units walking on the pathways, then you can get the realistic "town" feel.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
You should only create units as they are required and remove them as they are no longer useful. In an RPG it is pointless making end-game monsters if everyone is oly level 1 and pointless having beginning monsters running around if everyone is maxed out.

Hiding units will work to remove most of the resource drain the units cause as it works by de-attaching them from most of the game systems so they are no longer included in gameplay. They will still use other resources such as a handle id and memory for the actual data but this is so small it should make little difference for only a few hundred.
 
Level 4
Joined
Jul 20, 2012
Messages
83
Placing too many units might cause them to wait and stand still for awhile when ordered to do something/somewhere for like 0.5-1 second... it looks like they turn to the point where you order them to go and after that freeze of theirs they move... It's not something like a pc lag the fps runs smoothly but the units even on single-player do this, I've seen it many times in many maps...
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Placing too many units might cause them to wait and stand still for awhile when ordered to do something/somewhere for like 0.5-1 second... it looks like they turn to the point where you order them to go and after that freeze of theirs they move... It's not something like a pc lag the fps runs smoothly but the units even on single-player do this, I've seen it many times in many maps...
It is only if the units have to move and is caused by how WC3 handles computing movement. You can own 1000 move-able units and 12 of those units will still move fluidly if they are the only units moving.

There are two steps to moving a unit.
1. Path finding
2. Actual movement

The problem is caused by 1. WC3 keeps a circular list of all moving units for every player. Every game frame for every player it picks the next unit from the list and then runs the path finder on that unit. The result of the path finder is a "mini-move" order.

A mini-move order is a vector specifying a direction and distance a unit can safely walk to make it part-way to its destination. The key here is part-way, it is intended to only give enough walking distance until the unit is picked once again by the path finder and a new mini-move calculated. Of course the unit may never reach the end of its mini-move as in the case of only 1 unit moving, it will be getting updated constantly. The distance of a mini-move is not constant, complex pathing areas compute shorter mini-moves than large open spaces.

Part 2 does not help the problem. In addition to rotating and moving a unit towards a mini-move, it also handles unit to unit collisions. The collision handling algorithm used by WC3 is to cancel the current mini-move. With a few units this works well because it gives chance for the unit in front to move out the way or the pathfinder algorithm to work out a way around the units and since the unit will be given a new mini-move very fast it makes no difference. However if you are moving hundreds of bulky collision units you cause catastrophic trashing of the system.

During trashing, each unit is given a mini-move very seldom (seconds, humanly noticeable) as there are hundreds of units to update. However since the units are very tightly packed you get the problem of each mini-move only lasting a fraction of its intended distance as the unit very quickly collides with the one in-front. This causes movement slowing from both sides, not only a lack of mini-moves as their occupying time is less than the time between refreshes, but also because each mini-move is interrupted early. The end result is a huge army of hundreds of units moving like a caterpillar, 1 unit at a time forward in a chain.

So how do Tower Defense maps have hundreds of units moving at the same time without that problem? They distribute mobs among many players. Each player gets a pathfinder iteration per frame so two players can move twice as many units at once as one. They also give the mobs low or no collision, so they are allowed full mini-movement distance. Finally they use large open spaces (the paths) that allow long distance mini-move calculations.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
So how do Tower Defense maps have hundreds of units moving at the same time without that problem? They distribute mobs among many players. Each player gets a pathfinder iteration per frame so two players can move twice as many units at once as one. They also give the mobs low or no collision, so they are allowed full mini-movement distance. Finally they use large open spaces (the paths) that allow long distance mini-move calculations.

That is useful information. I only ever considered giving the enemy force more than 1 player. Didn't think about open space and collision. Nice.
 
Status
Not open for further replies.
Top