Documentation for our new global Interest Management system.
When making multiplayer games, the first obvious approach is to simply broadcast the world state to every player. By default, that's what Mirror does when you don't use any Interest Management components.
Instead of sending the full world state to every player, it's worth considering sending only what's around a player to the player. There are a few major reasons for interest management:
- Scale: imagine World of Warcraft. Sending the whole world to every single player would be insane. In order to scale to thousands of connections, we need to only send what's relevant to any given player.
- Visibility: in a MOBA game like DotA/League of Legends, not everyone should see everyone else all the time. A player should only see his own team and monsters around him. Not only that, but players shouldn't see behind walls etc.
- Cheating: in games like Counter-Strike, players naturally don't see enemies behind walls because the camera wouldn't render them. But if the whole world state is known in memory, then hackers could exploit that by showing players behind a wall anyway.
In other words, interest management is almost always a good idea.
Select the Network Manager and add one of the built in Interest Management components.
The new Interest Management API is fairly simple and allows for heavy customization. We walked through it with the distance based example, which is easy to understand.
You may have noticed that this is a global component, yet all the functions seem to work locally around one Network Identity at a time. There are two reasons for that:
- Our legacy Interest Management system worked on a per-Network Identity basis (or locally if you will). For the global system, we simply moved those functions into one global component.
- This allows for global solution like Spatial hashing, while also guaranteeing feature pararity and easy upgrades from the old systems.
- It's really just the old system moved to a different place. Don't fear it :)
- Interest Management can be quite complicated with all the spawning and despawning at the right time. Mirror has a whole lot of interest management code in
NetworkServer, which simply calls the three functions above.
- The idea is to shield you from all the complexity. All you need to do is worry about one Network Identity at a time. That's fairly easy to think about.