Arch.Extended: Cannot create entities after deserializing the world
I am trying to use Persistence in order to send the world state over to another client and continue simulation there. However, I am getting this error when trying to create entities after deserialization.
ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.
System.Array.Copy (System.Array sourceArray, System.Int32 sourceIndex, System.Array destinationArray, System.Int32 destinationIndex, System.Int32 length) (at <59a524f39437477884870e130f2eaa4f>:0)
System.Array.Resize[T] (T[]& array, System.Int32 newSize) (at <59a524f39437477884870e130f2eaa4f>:0)
Arch.Core.JaggedArray`1[T].EnsureCapacity (System.Int32 capacity) (at <f04907b0740a41dcb23e49fd4f7f024b>:0)
Arch.Core.EntityInfoStorage.EnsureCapacity (System.Int32 capacity) (at <f04907b0740a41dcb23e49fd4f7f024b>:0)
Arch.Core.World.GetOrCreate (System.Span`1[T] types) (at <f04907b0740a41dcb23e49fd4f7f024b>:0)
Arch.Core.World.Create[T0] (T0& t0Component) (at <f04907b0740a41dcb23e49fd4f7f024b>:0)`
This is enough to reproduce. Just create the world, serialize it and deserialize it, and when trying to create, it errors.
public struct Test
{
public int value;
}
ArchBinarySerializer serializer = new ArchBinarySerializer();
World = World.Create();
var bytes = serializer.Serialize(World);
World = serializer.Deserialize(bytes);
World.Create(new Test { value = 2 });
I also used ComponentRegistry but to no avail. One interesting behaviour, if I add the entity before serializing, the error is fired from the .Deserialize line instead. Here is that stacktrace, if it helps.
ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.
System.Array.Copy (System.Array sourceArray, System.Int32 sourceIndex, System.Array destinationArray, System.Int32 destinationIndex, System.Int32 length) (at <59a524f39437477884870e130f2eaa4f>:0)
System.Array.Resize[T] (T[]& array, System.Int32 newSize) (at <59a524f39437477884870e130f2eaa4f>:0)
Arch.Core.JaggedArray`1[T].EnsureCapacity (System.Int32 capacity) (at <f04907b0740a41dcb23e49fd4f7f024b>:0)
Arch.Core.EntityInfoStorage.EnsureCapacity (System.Int32 capacity) (at <f04907b0740a41dcb23e49fd4f7f024b>:0)
Arch.Core.Extensions.Dangerous.DangerousWorldExtensions.EnsureCapacity (Arch.Core.World world, System.Int32 capacity) (at <f04907b0740a41dcb23e49fd4f7f024b>:0)
Arch.Persistence.WorldFormatter.Deserialize (MessagePack.MessagePackReader& reader, MessagePack.MessagePackSerializerOptions options) (at <af3ea2856d7b42a2bd70a4676dc1a254>:0)
MessagePack.MessagePackSerializer.Deserialize[T] (MessagePack.MessagePackReader& reader, MessagePack.MessagePackSerializerOptions options) (at <e0125fc189a34138b45ca77ebe60d374>:0)
Rethrow as MessagePackSerializationException: Failed to deserialize Arch.Core.World value.
MessagePack.MessagePackSerializer.Deserialize[T] (MessagePack.MessagePackReader& reader, MessagePack.MessagePackSerializerOptions options) (at <e0125fc189a34138b45ca77ebe60d374>:0)
MessagePack.MessagePackSerializer.Deserialize[T] (System.ReadOnlyMemory`1[T] buffer, MessagePack.MessagePackSerializerOptions options, System.Threading.CancellationToken cancellationToken) (at <e0125fc189a34138b45ca77ebe60d374>:0)
Arch.Persistence.ArchBinarySerializer.Deserialize (System.Byte[] world) (at <af3ea2856d7b42a2bd70a4676dc1a254>:0)
I got the Persistence package from https://www.nuget.org/packages/Arch.Persistence, is it maybe outdated? I see there’s tag 1.0.8 on github, but I’m using Unity, and this is how I got it to compile.
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 17 (8 by maintainers)
Hmm, I might’ve been too hasty, I imported all the nuget packages that I had in unity and I can’t repro the bug in console app. In the end I ended up switching to Flax Engine, and the same code works there no problem (using net 7 dlls), so this is not as important to me anymore. Best way to repro would probably be to create a unity project, but I don’t blame you if you don’t fix this, since it might be related to unity and not your code.
So I created a new unity project, using version 2023.2.0b12. Then I added Arch and Arch.Persistence, here are the version numbers
I wrote the same script as above, and it still happens.
Could it be because I ran it in unity? Let me know if I can provide anything else. I’m also in the discord, under username noice.
I’m on 1.0.2 too. and 1.2.6.8-alpha for Arch. Later today I’ll try to repro with a fresh project.