An approach for generically de/serializing events? #9318
Unanswered
Architector4
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm messing around with Bevy and figuring a way to generically serialize, transfer and deserialize world state in realtime between multiple
World
instances. So far,DynamicScene
with a sprinkling of change detection works perfectly well for doing this with individual entities with components, and individual whole resources, but I'm unsure if there's a way to do it with events.The
Events<T>
resource itself is not serializable or even reflectable, and it wouldn't make sense for it to be, because its internal counters and stuff would turn into a large mess that won't work correctly anyways.One approach I'm thinking of is:
SyncedEvent (Box<dyn Reflect>)
type that implementsEvent
trait;EventWriter<SyncedEvent>
;Last
base schedule in sending world withEventReader<SyncedEvent>
that serializes and sends them to the other world;First
base schedule in receiving world that receives events, deserializes them, and makes them available withEventWriter<SyncedEvent>
to the rest of the ECS;EventReader<SyncedEvent>
and then tries to find ones it cares about and downcast them to the needed type.I suppose steps 2 and 5 could be simplified by making two system sets that convert between
SyncedEvent
instances and the actual types, where the systems that deal with the actual events don't need to care about them being transmitted all over the place.That would work, but sounds finicky and manual and is basically what I originally wanted to do with entities and components before I actually learned that
DynamicScene
is a thing. Is there a better approach using Bevy's built-in tooling that I missed or something?Beta Was this translation helpful? Give feedback.
All reactions