The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

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

FadiB
2019-09-19 17:26:13

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;  
}  

Comments

GLucas
2019-10-13 14:58:22

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.

Clevereen
2020-05-17 17:46:43

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?

Back to top