Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow serializing/deserializing Entity outside World #228

Closed
Rua opened this issue Jan 2, 2021 · 4 comments · Fixed by #230
Closed

Allow serializing/deserializing Entity outside World #228

Rua opened this issue Jan 2, 2021 · 4 comments · Fixed by #230

Comments

@Rua
Copy link
Contributor

Rua commented Jan 2, 2021

When trying to serialise a type that contains an Entity reference, outside a World, I get a panic with the error "No entity serializer set". Serializing an Entity reference requires run_as_context to be called in order to provide the thread-local variable containing the Canon. This function is private, which means it's not possible to serialize/deserialize any type that contains Entity if it's not in a component in the World.

Could something be added to allow serde of Entity outside a World?

@Uriopass
Copy link

Uriopass commented Jan 2, 2021

I think #221 solves this but I'm not sure what idiomatic code looks like using it. (note that this PR isn't part of the last released version)

@Rua
Copy link
Contributor Author

Rua commented Jan 3, 2021

Unfortunately it doesn't. The way to serialise Entity or types containing it would be something like this:

registry.with_entity_serializer(|canon| {
    run_as_context(canon, || {
        // do serialising here...
    });
});

This is more or less what the code here does. But with run_as_context being private, non-Legion code can't replicate it.

@matthewjberger
Copy link

matthewjberger commented Jan 3, 2021

I am seeing this as well

I'm storing copies of Entity in a scene graph outside of the legion::World. When the scene graph is empty (containing no copies of Entity) serialization works properly, but otherwise I get the No entity serializer set panic when serializing

@Uriopass
Copy link

Uriopass commented Jan 3, 2021

Well, in the meantime, I have a workaround for this.

Just before serializing, put structs containing entities in the world as single-component entities and serialize as normal. Then remove them from the world.

When deserializing extract theses structs and remove them from the world. Note that this workaround does a lot of copying :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants