Too many units in the map generates lag

Level 3
Joined
Oct 8, 2024
Messages
14
Hello everyone.
I made a map where the units have a maximum food usage of 1 for each unit.
My goal is that each player (1v1 map) can generate enough units without food being a problem and make more complex strategies (Like it was Age of Empires or Totalwar Warhammer).
However, my problem is that when moving a large number of units against rival units they generate lag, they do not respond well to movement orders (they slow down), but it is not a low fps, it only happens to the movement of many units selected and sent to fight at a specific point against other units.
What can I do to remove the lag?
The map has almost no triggers, it is very simple.
I would like someone to help me please.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Hello everyone.
I made a map where the units have a maximum food usage of 1 for each unit.
My goal is that each player (1v1 map) can generate enough units without food being a problem and make more complex strategies (Like it was Age of Empires or Totalwar Warhammer).
However, my problem is that when moving a large number of units against rival units they generate lag, they do not respond well to movement orders (they slow down), but it is not a low fps, it only happens to the movement of many units selected and sent to fight at a specific point against other units.
What can I do to remove the lag?
The map has almost no triggers, it is very simple.
I would like someone to help me please.
Reduce collision sizes and split units up among multiple players.
 
Level 3
Joined
Oct 8, 2024
Messages
14
Sadly I don't think there's a way, WC3 simply wasn't made for ultra large scale battles and at some point the engine just gives up and your orders are heavily staggered if not ignored completely
Well, it's not that I want to have 1000 units simultaneously.
My map has a limit of 100 units (which consume 1 food each) and I just want an improvement regarding that specific lag.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
And how can I do that? I don't know much other than adding models, modifying skills and attributes in general.
Each unit has it's own Collision Size which you can find in the Object Editor. Adjust it to 16 and see if that helps.

For dividing units among multiple players it's only really practical for Computer players. You could put two Computers on the same team, then using triggers you could change their Color / Name so that they look the same. Then simply use the "Change Owner" action to split them up. There are many tutorials on getting started with triggers (see my signature).
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
What Uncle mentioned is the only way to scale back this issue. It's not lag. It's the pathfinding algorithm being inefficient and unable to deal with finding proper paths for everything moving at once. If you look around you'll find a lot of threads about this because it's a common issue for people to run into. Reducing the collision size of units and distributing them equally among players is the only way to reduce this pathfinding issue.
 
Level 3
Joined
Oct 8, 2024
Messages
14
Each unit has it's own Collision Size which you can find in the Object Editor. Adjust it to 16 and see if that helps.

For dividing units among multiple players it's only really practical for Computer players. You could put two Computers on the same team, then using triggers you could change their Color / Name so that they look the same. Then simply use the "Change Owner" action to split them up. There are many tutorials on getting started with triggers (see my signature).
Thanks, I will try to change the collision.
But with the issue of dividing units between other players, can't it apply to another real player?
That is, in case you want to play against another person.
 
Level 3
Joined
Oct 8, 2024
Messages
14
What Uncle mentioned is the only way to scale back this issue. It's not lag. It's the pathfinding algorithm being inefficient and unable to deal with finding proper paths for everything moving at once. If you look around you'll find a lot of threads about this because it's a common issue for people to run into. Reducing the collision size of units and distributing them equally among players is the only way to reduce this pathfinding issue.

Yes, that's what I found out after doing a lot of research.In that case, can't I somehow disable that artificial motion intelligence? Or somehow, make it simple and don't try to accommodate it as such.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Thanks, I will try to change the collision.
But with the issue of dividing units between other players, can't it apply to another real player?
That is, in case you want to play against another person.
You have to be able to control the units, so dividing it between other players is tricky. You could try sharing full control of the "fake" allied player but I imagine there will be all sorts of undesirable side effects.
 
If you allocate 80 units per player, you can avoid this lag, I don't do trigger nor jass so I can't give much detail :

-Make it so player 3 is allied with player 1, player 4 with player 2 and share full control between those players so the human player can control the units of the "fake" players
-Each player must have a group registering their units (I said group but idk which data structure is used in trigger, other will correct me)
-Upon a unit creation, register the unit in the group, if the group size is > to 80, you have to change the unit owner & its color to player 3 or 4.

That's the first step to solve this problem, there are other issue regarding ordering all those units, now I got back to work :X


I solved this issue in my map, here's a battle example :
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
-Each player must have a group registering their units (I said group but idk which data structure is used in trigger, other will correct me)
-Upon a unit creation, register the unit in the group, if the group size is > to 80, you have to change the unit owner & its color to player 3 or 4.
I'd recommend something like this to avoid checking group size (has to loop over the entire Unit Group to count them up):
  • Events
    • Map initialization
  • Conditions
  • Actions
    • -------- Setup P1 (Red) data --------
    • Set Variable Player_Ally[1] = Player 13 (Maroon)
    • Set Variable Player_Owner[1] = Player 1 (Red)
    • Set Variable Player_Count_Self[1] = 0
    • Set Variable Player_Count_Ally[1] = 0
    • -------- Setup P2 (Blue) data --------
    • Set Variable Player_Ally[2] = Player 14 (Navy)
    • Set Variable Player_Owner[2] = Player 2 (Blue)
    • Set Variable Player_Count_Self[2] = 0
    • Set Variable Player_Count_Ally[2] = 0
Whenever you want to create a unit you would Set the Player_Number variable beforehand and run this trigger:
  • Events
  • Conditions
  • Actions
    • If all (Conditions) are true then do (Actions)
      • If - Conditions
        • Player_Count_Self[Player_Number] Less than 50
      • Then - Actions
        • Set Variable Player_Owner[Player_Number] = (Player(Player_Number))
        • Set Variable Player_Count_Self[Player_Number] = (Player_Count_Self[Player_Number] + 1)
      • Else - Actions
        • Set Variable Player_Owner[Player_Number] = Player_Ally[Player_Number]
        • Set Variable Player_Count_Ally[Player_Number] = (Player_Count_Ally[Player_Number] + 1)
    • Unit - Create 1 Footman for Player_Owner[Player_Number]
Footman could be a variable as well since you'll likely be creating many different types of units.

Then when a unit dies you can update the total remaining:
  • Events
    • Unit - A unit owned by Player 1 (Red) Dies
  • Conditions
  • Actions
    • Set Variable Player_Number_Dies = 1
    • Set Variable Player_Count_Self[Player_Number_Dies] = (Player_Count_Self[Player_Number_Dies] - 1)
  • Events
    • Unit - A unit owned by Player 2 (Blue) Dies
  • Conditions
  • Actions
    • Set Variable Player_Number_Dies = 1
    • Set Variable Player_Count_Ally[Player_Number_Dies] = (Player_Count_Ally[Player_Number_Dies] - 1)
Something like that, it could be more efficient by using a Unit Indexer/Hashtable to track and organize the data as well as extend it to allow multiple CPU's per Player.
 
Last edited:
Level 24
Joined
Feb 27, 2019
Messages
833
Something that could reduce the amount of moving units is to make resource gathering less intense, though it seems to be low intensive already, by f.e. using the NE's and UD's gathering method for gold or NE's or a Shredders gathering method for wood. It would alter game-mechanics but sometimes game-mechanics are born from unintended bugs or necessity. Though its more like putting a band-aid on the actual problem.

An idea that came to mind was to allocate unused units to another player, much like how trees and models are hidden when youre not looking at them in some fps to save resources. The allocation could be based on selecting units and or current camera. It does sound like it would require a bit of a plan and some work to create a whole system and rules, per heaps not fitting for you.

Adding the ability Ghost (Visible) to units does make an insane difference but the cost for game-mechanics is very high since it allows units to walk through eachother. Not worth it in my opinion.

Giving units the is a building true makes their pathfinding much dumber but has a lot of sideeffects and doesnt really seem to fix any problems.
 
Level 18
Joined
Feb 2, 2009
Messages
217
Everything said in here is valid but to add to the discussion understand that terrain complexity has the potential to add to unit lag as well.

The more loopy your pathing tends to be between a unit and its destination point the longer it takes for each unit’s pathfinding to really work effectively. It’s another part of why blood tournament style games work so effectively as there are relatively few obstacles between the units and their next destination.

Where possible in these types of games try to keep things fairly ‘open’, and of course you can tighten things up if you reduce collision/movement speed/units per player
 
Level 3
Joined
Oct 8, 2024
Messages
14
Thank you all very much, seriously
I didn't think I would have so much help right away, they are great friends.
I will try to apply your advice and let you know if it works for me.
I'll look into the issue of sharing units with other players to see what happens.
Of course, I will give details of my map so you can get an idea of what it is like:

First, it's like standard Warcraft 3, with resource gathering at the start of each game and all that.
There are no heroes here, only Tier 1, 2 and 3 units

The cost of each technological level and upgrades is increased for a slower game where controlling troops is more vital.
Defense buildings have much more life (Defences are scary for the damage and durability).

All units' health was reduced to a maximum number (Example: Footman, 60 life points and 7 attack points, but the buildings retain their health points greater than 1000).

This makes the demolition artillery units have more presence, because they have a maximum of 255 total damage, but they are quite vulnerable and slow.
Everything is based on defending at the beginning and attacking with head in the Endgame stage.

And I also made a "Counter" system so that certain units are more effective against others and there is a balance for each situation.
There will be small gold mines scattered around the map and in general, everything is done to give importance to the use of towers and acquiring territories throughout the map.
And that is why the issue of lag is vital for me when there are somewhat large battles.

And I explain this to you so that you can see more or less what I am trying to achieve.
 
Level 3
Joined
Oct 8, 2024
Messages
14
Everything said in here is valid but to add to the discussion understand that terrain complexity has the potential to add to unit lag as well.

The more loopy your pathing tends to be between a unit and its destination point the longer it takes for each unit’s pathfinding to really work effectively. It’s another part of why blood tournament style games work so effectively as there are relatively few obstacles between the units and their next destination.

Where possible in these types of games try to keep things fairly ‘open’, and of course you can tighten things up if you reduce collision/movement speed/units per player
Sorry, this may not be related to the topic of this Forum, but I just changed the multi-unit collision size to 8.
I don't know if it is the cause, but after putting in a certain number of units this problem appeared here.
Like the models are deformed, but it happens when I put a large number of knights.
 

Attachments

  • Capturagrtgt.PNG
    Capturagrtgt.PNG
    1.7 MB · Views: 18
Level 18
Joined
Feb 2, 2009
Messages
217
Sorry, this may not be related to the topic of this Forum, but I just changed the multi-unit collision size to 8.
I don't know if it is the cause, but after putting in a certain number of units this problem appeared here.
Like the models are deformed, but it happens when I put a large number of knights.
Ah this is another common thing for Warcraft 3. Too many polygons on the screen at once make the game get all fritzy and causes little spaghetti vectors to project to different corners.

Models with more polygons are more prone to causing this issue I believe, and some custom models can have a ton or other errors that make it occur more easily.

With the collision set to 8, a lot of units are now on the screen. I’m not sure what game version your on, but this occurs less on the current patch from my experience compared to say Warcraft 3 in 2013.

You may want to look at lower poly alternatives for the units (especially those custom knights on the left if memory serves). But also I’ll lean into recommending that you try to reduce unit numbers into something more feasible. There is no reason that your awesome vision has to be riddled with inconvenient engine limitations when you can likely achieve the same oomph with fewer units. Keep in mind that most melee games typically only boast armies comprised of about 10-23 units!

A game where you have about 60 or so units in your army that you’d have to micro would still be grand and probably more feasible of a learning curve given the limits of what Warcraft 3 offers as far as unit selection.

Hope any of this helps and sorry to see you running into so many engine-oriented roadblocks!
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
If you just want the visual effects of a large scale battle then you could take advantage of Special Effects. I imagine they won't cause the same issues.

One of these days I want to create a squad system where one real Unit acts as the "leader" of a fake squad of units. So the leader is surrounded by X special effect "fake units" that follow his orders. As he takes damage, the special effect units die off. For every 10% lost life = 1 of the 9 sfx destroyed, with the last 10% of life counting towards the leader. Could be pretty cool, although a major pain in the ass to get right. It would mimic something like the squads in company of heroes. Anyway, just a neat idea that would serve well for a map like yours.
 
Top