Closed Shatur closed 2 months ago
There is a problem with this. EntityMapper
doesn't provide a way to handle errors. I can panic or keep invalid entity in the component, but I can't stop the serialization:
https://github.com/projectharmonia/bevy_replicon/blob/3d48f5a0300c27200c1e3014d62269ead1032715/src/core/ctx.rs#L90-L98
I think emitting a warning and keeping component in an invalid state is not a good idea...
Maybe add try_map_entity
method to EntityMapper
that defaults to Ok(Self::map_entity(entity))
.
If EntityMapper
have two methods, user will have too decide between them in their MapEntities
impl.
I.e. the component have to be aware about the mapping usage, which is not good...
True. You could just replace EntityMapper
with a new EntityMapperChecked
trait.
Users will need to implement both which is also not great... 🤔
I used panic because I thought that it's impossible to happen 😅 But forgot to take visibility into account. It was reported that sending an event that contains an entity that isn't visible for a client causes crash. I think we should ignore this event and change the panic into a warning.