Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Save/Load Obi Rope state and rope network state synchronization
#7
(24-05-2021, 12:16 PM)pmike Wrote: Another question: how to effectively serialize and deserialize object of type ObiNativeVector4List? 

Direct serialization via BinaryFormatter does not work:

SerializationException: Type 'Obi.ObiNativeList`1[[UnityEngine.Vector4, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'Obi, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

But type


namespace Obi
{
    [Serializable]
    public class ObiNativeVector4List : ObiNativeList<Vector4>
    { ...

ObiNativeList internally holds a raw pointer to unmanaged data, so BinaryFormatter won't work. Furthermore, serializing the entire list does not make much sense in this context, as you're interested in the data for each individual actor, not the entire solver. There's no guarantee data belonging to different actors will be laid out in memory in exactly the same way in different machines.

Internally we use Unity's ISerializationCallbackReceiver interface to manually serialize/deserialize this data using unsafe operations (Unity.Collections.LowLevel.Unsafe), however this is *unsafe* as the name implies and can easily crash if you're not 100% sure of what you're doing.

Easiest way is probably to just iterate trough the list manually and serialize each entry to a format of your choice.
Reply


Messages In This Thread
RE: Save/Load Obi Rope state and rope network state synchronization - by josemendez - 24-05-2021, 12:26 PM