(Unity) Serializing a ScriptableObject containing struct arrays containing Vector3, Quaternions etc

In my game, I have a ScriptableObject that contains multiple struct arrays that in themselves contain data like Vector3, Quaternion, int and string.

If I want to serialize the entire ScriptableObject, what would be the best way to go about it?

I would essentially have to serialize the contents of the ScriptableObject and then do serialization on the structs, and then have to pass the vector3 values and quaternion values to the other players.

Or is there a better way to go about doing this?

I already know how to serialize int, strings and normal arrays, But I am unsure how Photon will handle this level of nesting that needs to be serialized and sent over the network.

Also I am not sure if I would need to serialize the Vector3 and Quaternion inside the structs or if Photon could handle that for me.

Any help would be greatly appreciated!

To demonstrate an example of what I am working with:
using UnityEngine;

[System.Serializable]
public struct ObjectData
{
    public Vector3 position;
    public Quaternion rotation;
    public bool isActive;
    public int objectID;
}

public class Player : ScriptableObject
{
    public int playerID;
    public int totalScore;
    public ObjectData[] myObjectDatas;
}

Answers

  • I definitely wouldn't advise any complex array structure being serialized and sent over the network like this, especially since i would assume all players would need to be doing this and that can bog you down a deal.

    You can attempt to turn the base object into a JSON string and then turning that into a byte array for sending, however i can promise this wouldnt be valid nor optimal in any case.
  • Hello,

    i have exactly the same question, i have a scriptable object that needs to be sent. When i do so, it seems the scriptable object is completely empty.

    did you find the solution?