Serialization Again

Today I spent some time to dive deeper than usual into ECS sources
and in Unity.Entities.Properties I’ve found an interesting class that was never mentioned:

JsonVisitor

I wonder how to use it?
Does it mean that it is possible somehow to serialize an entity to JSON?

Alos at bottom of EntityIMGUIVisitor I’ve found a compiler directive #if ENABLE_PROPERTY_SET
does it mean that there is some hidden way to tweak components data using entity debugger?

What is the estimate on working entity inspector?

Have you checked the EntityContainer at Unity.Entities.Properties?

var container = new EntityContainer(EntityManager, entity);
var json = JsonSerializer.Serialize(ref container);
1 Like

Yea, this is working, why this wasn’t mentioned anywhere in docs or on this forum…

Next question is: what about deserializing it back? How to do that?

https://devdog.io/blog/odin-serializer-goes-open-source/

unfortunately, there is no ECS support in this impressive list

Seems that no proper deserialization is set yet on EntityContainer, the only way I think for now is to JsonSerializer.Deserialize, then manually iterate the components in the resulting object adding/creating them on an EntityManager.
There may be another way by using this visitor pattern classes at Unity.Entities.Properties/Unity.Properties but I haven’t looked at it yet. :frowning:

1 Like

EntityComponent class contain sealed class ReadOnlyComponentsProperty
with a comment to it, that says:

so it looks like deserialization using visitor is not implemented