So given that my original aim of this thread was to make sure I had my facts about edicts correct before I tried exaplining them to others, I decided the best way to do this would be to re-phrase this thread as a guide which I will
publish on Steam.
Before I do that though, I'd like it if people could take a look at it to proof-read and fact check it. At the very least, some feedback on the structure would be appreciated. Bear in mind, I've tried to write it for casual players and/or people who don't know anything about mapping. But feel free to leave whatever feedback you want to!
Oh and sorry for the long read ahead, it's about 2800 words.....
~~~~~~~~~~~~~~~~~~~~
Understanding Entities, Edicts and the 'ED_Alloc: no free edicts' error
About this guide
This guide is intended to help average, normal players get a better understanding of how the Source engine works and some of the things that effect its performance, but hopefully mappers and server admins will also find this useful.
This guide has been simplified meaning a lot of the technical details have been left out. In other words, it's a bit more complex than how it is presented here, but this guide should help you understand the basics.
The Basics
An entity is pretty much anything in a map that does something. This includes the background game logic, lights that turn on or off, signs that move, invisible brushes and sounds you hear in the map. Some entities have to be coordinated between all the players on a server, so that everyone sees and hears the same things at the same time. If an entity has to be coordinated, that makes it an Edict. A rule of thumb that can be used to work out if something is an edict is "does it move or change color?"
You might have seen the gif below elsewhere on the internet. It was taken from the Battlefield 3 single player campaign, but imagine if it happened on a multi-player game. How confusing would it be if some players were able to see and shoot through a door as if it was open, while other players could not because the
same door was closed for them?
The Source engine can support a
maximum of 2048 edicts at a time. This sounds like a very high number, and to be fair it is. However between maps and players, the number of edicts in use can fill up quite quickly. Should a server reach 2049 edicts, the server
will crash with a "ED_Alloc: no free edicts" error.
While a lot of things are edicts, not everything is. Decals and ragdolls from dead players are not edicts because they don't effect gameplay, and individual players can disable both decals and ragdolls to improve their FPS in-game. Skins on redecorated weapons are not edicts either as they are props with extra data. The weapons themselves are edicts, but the skins don't add any extra edicts. But more on that later.
The Maps
The number of edicts a map uses will vary from map to map, but it won't change over time unless the map itself is changed. So how many edicts do map actually use? As there are
currently 101 maps currently included in TF2, plus hundreds of custom maps, lets stick with the edict counts for the 6 maps that came with TF2 on launch:
- cp_gravelpit - 506 (24.70%)
- cp_granery - 698 (34.08%)
- cp_dustbowl - 1027 (50.14%)
- ctf_2fort - 1050 (51.26%)
- cp_well - 1301 (63.52%)
- tc_hyrdo - 1470 (71.77%)
- Note: These are as of the time writing this guide, not the number of edicts these maps had back in 2007 as each map has had some form of update since launch.
The percentages beside each count is how much of the 2048 edict limit each map uses up when loaded on a server with no players or bots. That 2048 sounded like a lot, but then a map like tc_hydro take up nearly 72% of the available edicts! As we can see the amount of edicts taken up by maps can vary hugely and can quite easily take up most of a servers resources. But what about the players?
The Players
Players, like maps, can have different edict 'costs'. A basic, vanilla player with no cosmetics or unusual weapons, would have:
- 1) An invisible hitbox
- 2) A player model
- 3) A primary weapon
- 4) A secondary weapon
- 5) A melee weapon
In comparison, what would a fancy tricked out player 'cost' a server? Functionally speaking hats and weapons are treated as
prop_dynamic's parented to the players heads or arms. Similarly all unusual effects are an
info_particle_system parented to the prop_dynamic. That would certainly make them entities, but also edicts as those props and particles have to move about the map with the player. Assuming a worst case scenario, that player would also have:
- 6) a hat
- 7) a unusual effect on the hat
- 8) a unusual effect on the active weapon
- 9+10) cosmetics in the other two slots, and
- 11) an item in the action slot.
So players can vary in edict costs anywhere between 5 - 11 edicts per player, just from their cosmetics alone. A full 24 player server could use anywhere between 120 - 264 edicts, or an average of 192 edicts.
But what happens when they leave spawn and start firing those weapons? All weapons will have a sound effect that plays when the weapon is fired so that people know it has been fired. This is important as it give players rough information about where other players are and what they are doing. From here, hitscan and projectile weapons function differently.
Hitscan weapons create a particle effect when fired, most commonly as a muzzle flash. As there is no physical projectile, the game simply calculates what the imaginary bullet would have hit and takes away health accordingly.
Projectile weapons on the other hand produce a lot more edicts as every individual projectile is an edict because the movement of those projectiles has to be coordinated between players. They may also have extra particle effects if it is a crit to indicate that it is a crit.
Finally, what about dead and spectating players? These players actually cost the same as living players as the game simply reserves a number of entities aside while the players are dead or spectating.
Situation Comparisons
We've looked at the maps and players separately, now lets see what their combined edicts counts can be under various situations.
Let's start by comparing how a TF2 server would have been back in 2007, with a server under today's conditions, just to see how many edicts each would use up.
To keep things fair as possible, we going to make each the 'worst case scenario' for what was possible at the time. So each scenario will feature 2 full teams of demomen playing on the largest maps available, with every player placing the maximum number of sticky-bombs possible and then unloading their grenade launchers.
TF2 in 2007 (Vanilla)
- Full, 24 player server playing tc_hydro. So we have a starting number of 1470 edicts just from the map itself.
- Players consist of just a hitbox, model and their 3 weapons. 5 x 24 = 120 edicts
- The default stickybomb launcher can lay a maximum of 8 stickies at a time. 8 x 24 = 192 edicts
- The grenade launcher has 4 pills in a clip. 4 x 24 = 96 edicts
- TOTAL: 1470 + 120 + 192 + 96 = 1878 edicts.
That's 91.69% of the engine limit of 2048, leaving just 170 spare edicts. But it is within the engines limits, so its OK.
TF2 in 2017
- Full, 24 player server playing pl_thundermountain, which is the has the largest entity count in the current map pool. This map weighs in at 1566 edicts just from the map itself.
- Each player would have their model, hitbox and 3 weapons (as before). 5 x 24 = 120 edicts
- Assuming each players has an unusual item in all 3 cosmetic slots, that's an extra 6 edicts. 6 x 24 = 144 edicts
- Add in the unusual effect on the active weapon. 1 x 24 = 24 edicts
- Lets also assume that all 24 players have an unusual taunt, each consisting of a prop_dynamic and info_particle_system. After unloading their grenade clips, they use the taunt. 2 x 24 = 48 edicts
- Instead of the default stickbomb launcher, the players use The Scottish resistance as it can lay a maximum of 14 stickies at a time. 14 x 24 = 336 edicts
- The grenade launcher has 4 pills in a clip. 4 x 24 = 96 edicts
- TOTAL: 1566 + 120 + 144 + 24 + 48 + 336 + 96 = 2334 edicts!
That's 113.96% of the engine limits! In fact, that's a dead server! We could repeat this example with a 32 player server, but as we've killed the server with just 24 players it's not necessary.
An average TF2 server
Of course this is not how most servers are. Not every player has an unusual, let alone enough to fill all their cosmetic slots. Earlier we established that players can 'cost' a server between 5 and 11 edicts just for their loadout, which gives us an average of 8 edicts per player. Or an average of 192 edicts for a full server of 24 players.
What's harder to work out an average for is the number of projectiles spawned by players. In our worst case scenario, everyone was a demoman unloading the maximum number of stickies and grenades to create a sudden (if short lived) spike in the number of edicts. Of course, no server is ever like that. So we'll use the average counts of both of our previous scenarios to get a ballpark figure.
In the 2007 scenario, we had
288 edicts generated by players placing stickybombs and shooting grenades, while in the 2017 scenario we had
432 edicts from them doing the same, plus an extra
48 edicts for using unusual taunts, giving
480 edicts in total. This gives us an average of 384 edicts coming from player generated projectiles. As this is for a 24 player servers, that's 16 per player
Finally we have the maps. To get a completely accurate number would require inspecting all 101 maps to learn their individual edict counts, which would be a time consuming task. I may get round to this in the future, but for now as we looked at the 6 launch maps before, we'll use them along with pl_thundermountain to get a
very rough average number of map edicts:
- cp_gravelpit - 506
- cp_granery - 698
- cp_dustbowl - 1027
- ctf_2fort - 1050
- cp_well - 1301
- tc_hyrdo - 1470
- pl_thundermountain
- Total: 506 + 698 + 1027 + 1050 + 1301 + 1470 = 7618. 7618 divided by 7 = 1088 edicts.
So for a putting it all together, we have:
- An average of 8 edicts/player for their loadouts. 8 x 24 = 192 edicts
- An average of 16 edicts/player from projectiles. 16 x 24 = 384 edicts
- An average of 1088 edicts per map
- Total 192 + 384 + 1088 = 1664 edicts.
That's 81.25% of the 2048 edict limit, which is in the safe limit, but closer the cap than we would like.
Conclusions
So why did we look at the number of edicts that players, projectiles and maps all use? The point was to make you aware of how close any given server gets to the edict cap. Remember that once a server hits that limit, it crashes with the "ED_Alloc: no free edicts" error.
Something to remember with all these average counts is that the number of edicts will go up and down during the game. The peak time for entities is most likely to be after the start of a new round when players first make contact with the enemy team, as you have the most amount of players alive and firing their weapons. After that point there will almost always be someone dead or making their way back into battle.
Seeing as we've seen counts that go over the 2048 limit, it is very possible for a server to crash, and much easier than it was back in 2007 when TF2 launched. This has been in part due to new weapons and mechanics such as taunts, grappling hooks and unusual effects, but also maps that use edicts to run.
All throughout this we've only used maps from normal game modes. Custom gamemodes can potentially take up more edicts as they adjust different factors. 10x servers would be the best example of this as those server will multiply the number of projectiles a weapon can shoot by 10. Those server have to cut corners in other ways to limit the number of edicts in order to keep the servers up and running.
So what about in the future? We're good for now, but if Valve adds more weapons or mechanics they will have to be very careful how they do that. This isn't talking about what ever weapon being balanced or complementing other weapons, just that should they add another weapon then that weapon could generate edicts when used.
As for any map Valve adds, that too will have to have as few edicts as possible. This is something the wider mapping community has know for a long time and Valve know it as well. If you are a mapper, take a look at your own maps and see what they cost servers. It's always a good idea to see if you reduce the number of edicts you use.
As for Source2, it does have a higher limit in the one game so far that uses it. DOTA2's edict limit is 32,768. That's 16 times larger than Source's limit. Or another way of thinking about it, would be up grading your PC's RAM from 2GB to 32GB. It has been confirmed that CS:GO will get ported to the Source2 engine and that will likely see the same edict limit. TF2 on the other hand, is unlikely to get ported over to Source2.
I'm a server admin, what can I do to prevent edicts from building up on my server?
This greatly depends on what sort of server you are running, but there are some things you can do.
- If you notice you server crashes when it runs a specific map, remove that map from your server rotation. If it's a custom map, try to contact the maps maker to see if they update the map. However it could be that the map crashes the server for other reasons and the map is well under the edict limit. In any case, it doesn't hurt to ask the mapper if they could take a look at their maps edict count and to try reduce it where they can.
- If you want to see what the number of edicts for a map is, load the map by opening the developer console and typing map <map_name>, then enter. So if I wanted to load 2 fort, I would type map ctf_2fort. Once the map has loaded, join spectate. Open the console again and type status. It will give you an output of various details about the server, one of which is number of edicts.
Code:
edicts : 1049 used of 2048 max
You can take that number then add 576 to it. If the number you get as a result is more than 1639 (80.02%), then the chances are that map may crash your server during heavy play.
- Disable cosmetics. This can be done with serverside plugins, and by removing cosmetics you will reduce the number of entities in use by each player
- Run 24-player server instead of 32-player servers. Yes it's more fun to have more players, but more players means more edicts.
- Consider adding class-limits. This isn't a popular option, but different classes generate more edicts than others. The point here to prevent there being to many edict heavy classes like the demoman at once. Class limits would, in theory at least average out the number of edicts used per player. In other words, any extra edicts used by one class get saved from another class.
Sources: