#How to serialize the World?

1 messages · Page 1 of 1 (latest)

golden coyote
#

There is SerializeUtility.SerializeWorld, but this will display

ArgumentException: Blittable component type 'Unity.Physics.SimulationSingleton' contains a (potentially nested) pointer field. Serializing bare pointers will likely lead to runtime errors. Remove this field and consider serializing the data it points to another way such as by using a BlobAssetReference or a [Serializable] ISharedComponent. If for whatever reason the pointer field should in fact be serialized, add the [ChunkSerializable] attribute to your type to bypass this error.

so alright, SimulationSingleton contains a pointer, we probably don't want to serialize this anyway. so I move this out of the world, and try again.
then I get the same issue for Unity.Entities.BlobAssetOwner, but this time it's internal, so it seems we can't make a query for it?

it seems like a lot of Unity components are containing pointers now, wasn't the point of Unity.Physics that it's stateless??

I could probably get around this by writing a custom serializer and ignore components with pointers, but this probably won't be deterministic, I'm looking for a deterministic way.

what is the intended way of serializing and deserializing a world deterministically?

lunar breach
#

If you're doing this for saving don't serialise the entire world with these methods

#

Any component change would break all your users save data

golden coyote
#

yeah, this isn't for saving, for saving i'd go with storing specific components

#

i just want to make a 1:1 deterministic copy of the world that i can save to disk and reload from

#

no versioning needed

proven yacht
#

I'm working on the same goal. @golden coyote might be nice to chat as you get further in. SerializeUtility is built for serializing subscenes to disk for level streaming, but isn't designed to serialize a 1:1 copy of a runtime world .

#

Many built in ECS systems have pointers, or generally other non blittable data that will not serialize without a bit of extra work.

#

My strategy for this problem was to serialize the entities but not the system state / system entities. Or handle them manually as an additional step.

golden coyote
#

had another go at this
instead of serializing to disk, I'm now just attempting to 'save' and 'load' by moving the entities from one world to another

this seems to work without physics systems, but if you add Unity.Physics systems to the world, there's a bunch of memory issues when using EntityManager.CopyAndReplaceEntitiesFrom and then trying to update the world. I think there's something going wrong with cached values in Unity.Physics

unity is claiming Unity.Physics to be stateless, am I missing something?