cBournhonesque / lightyear

A networking library to make multiplayer games for the Bevy game engine
https://cbournhonesque.github.io/lightyear/book
Apache License 2.0
496 stars 51 forks source link

bevy_ecs::world: error[B0003] for `Predicted` and `Interpolated` entities on client disconnect #690

Open sQu1rr opened 1 week ago

sQu1rr commented 1 week ago

Hey there!

I noticed this warning when a client disconnects with entities that have prediction or interpolation enabled. It’s a harmless one but still a bit annoying, so it'd be great to find a way to silence it. Unfortunately, I don’t have a perfect fix in mind, but here’s what I’ve found.

What I’m Seeing

When the client disconnects, it throws this warning:

WARN bevy_ecs::world: error[B0003]: Could not despawn entity Entity { index: 54, generation: 2 } because it doesn't exist in this World. See: https://bevyengine.org/learn/errors/#b0003

Steps to Reproduce

What I Think is Happening

After some investigation, here’s my theory:

  1. On client disconnect, the OnDisconnect schedule runs, which queues the removal of all Replicated, Predicted, and Interpolated entities for the next tick (?).
  2. Then, after entities are removed, the removal triggers for both the predicted and interpolated systems also activate, re-queuing removal for entities that were already removed.
  3. Finally, I get the Bevy ECS error, which makes me think the error is triggered by these double-queued entities.

Possible Solution?

Entities that are already removed should be skipped, though I’m not entirely sure how to tackle this. I hope my little investigation here helps narrow down a fix!

Thanks!

cBournhonesque commented 2 days ago

You're right, those error messages are due to the Disconnect schedule which tries to despawn any replicated entity. It queues a despawn Command, and there's probably some other palce in the codebase which also queues a despawn command.

I would think that this wouldn't happen since I'm guarding despawns with if let Some(entity_mut) = commands.get_entity(predicted) { but maybe not!