OnPhotonSerializeView: No more than 5 items?
Options
Hey guys,
i just started coding with Unity and the Photonnetwork-Plugin.
Not I have to sync some Variables and use the "Photon View" and "OnPhotonSerializeView"-Method for it.
The Problem is, that no matter how many variables I send my "stream.SendNext()" only the first 5 of them will be available by "stream.ReceiveNext()"
Now I tried to build a serializable Class to contain all the Data but it is giving me an Error: "Exception: cannot serialize(): PNSendPackage".
Am I going for the completely wrong way on this sync or is there a viable solution how I can fix it?
Greetings
Neokil
i just started coding with Unity and the Photonnetwork-Plugin.
Not I have to sync some Variables and use the "Photon View" and "OnPhotonSerializeView"-Method for it.
The Problem is, that no matter how many variables I send my "stream.SendNext()" only the first 5 of them will be available by "stream.ReceiveNext()"
Now I tried to build a serializable Class to contain all the Data but it is giving me an Error: "Exception: cannot serialize(): PNSendPackage".
Am I going for the completely wrong way on this sync or is there a viable solution how I can fix it?
Greetings
Neokil
0
Comments
-
You can definitely send more than 5 items. Maybe something went wrong writing or reading them.
This "Exception: cannot serialize(): PNSendPackage" sounds like this is the problem. You can't send arbitrary types. Either convert the info you need to other types or a byte[] or add your class to the serializer. You can see how it's done in CustomTypes.cs.0 -
Thanks for the help.
I will have a look at the CustomTypes for that.
But maybe you can have a quick look at the Code below. It is my OnPhotonSerializeView-Method where I send 7 Objects but only 5 are given back.void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if(stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(anim.GetFloat("Speed"));
stream.SendNext(anim.GetBool("Jumping"));
stream.SendNext(anim.GetBool("Die"));
stream.SendNext("Testtext 1");
stream.SendNext("Testtext 2");
}
else
{
Debug.Log(stream.Count); //Is always 5
realPosition = (Vector3)stream.ReceiveNext();
realOrientation = (Quaternion)stream.ReceiveNext();
anim.SetFloat("Speed", (float)stream.ReceiveNext());
anim.SetBool("Jumping", (bool)stream.ReceiveNext());
anim.SetBool("Die", (bool)stream.ReceiveNext());
stream.ReceiveNext(); //Out-of-bounds-Exception
}
}0 -
I tested with the code below and it gives me 7 items.
For testing, can you first assign the values each to some temporary variable, then add them to the stream?
[code2=csharp]void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
stream.SendNext(1.0f);
stream.SendNext(true);
stream.SendNext(false);
stream.SendNext("Testtext 1");
stream.SendNext("Testtext 2");
}
else
{
Debug.Log(stream.Count); //Is always 5
Vector3 realPosition = (Vector3)stream.ReceiveNext();
Quaternion realOrientation = (Quaternion)stream.ReceiveNext();
float a = (float)stream.ReceiveNext();
bool b = (bool)stream.ReceiveNext();
bool c = (bool)stream.ReceiveNext();
stream.ReceiveNext(); //Out-of-bounds-Exception
}
}[/code2]0 -
Thanks for the advice.
When i use local variables to save the data and then send those, it works properly.0