Synchronizing Deleted Entities



Today I worked on figuring out how to detect if an entity was deleted, but the delete message didn’t make it to the client. This currently only happens when a client has a disconnect period, during which the server sends delete messages. This means that the client loses those delete messages, causing it to think an entity is still active, when in reality the entity has been deleted (e.g. a user has logged out).

I had two ideas:

  1. Have each client probe the server on suspicious entities (ie entities that it hasn’t heard from in a while) to see what their status is.
  2. Have a timeout that triggers after a while to just automatically delete entities that haven’t sent updates in a while.

I realized that these could both work together, so I decided to just initially write the timeout code, and if I wanted more complex probing logic. I can add that later.

Figure 1: Me figuring out how to synchronize deleted entities. Green: Active, Blue: Inactive, Red: Deleted

The figure above is my sort of rationalization. As the world space increases, there will be some sphere of vision that each player has (The white circle). We certainly don’t want to send the entire world in every update message, as that would waste a lot of bandwidth for entities that are too far.

Another “missed delete” case can happen when something outside our vision sphere is deleted, and later on enters our vision sphere (because we walked back over that area where it was). At this point we don’t know what the state of that entity is. Is it deleted? Is it just standing still? Has it moved somewhere completely different?

So to handle all of these I decided to have 3 levels of “activity”:

  1. Active (Green): Entities that we have recently received info about from the server.
  2. Inactive (Blue): Entities that we haven’t heard from in a short time.
  3. Deleted (Red): Entities that we haven’t heard from in a long time.

On the client side, we can handle each of these cases like so:

  1. Active (Green): Treat this entity like it currently exists in the game
  2. Inactive (Blue): Treat this entity like we are unsure if it exists. This means keeping it around in our ECS world, but probably not rendering it. By keeping it in the world, if/when we get the next positional update from the server on it. We can easily just render the entity without having to probe all of the data about it.
  3. Deleted (Red): Delete this entity from our ECS world. This means that we’ll need a full update on the entity if we happen to run into it in the future.