Syncing State of Large List of Children Transforms Using OnPhotonSerializeView
Options
I'm attempting to sync position, rotation, and scale for a large list of children gameobject under a root gameobject that has a PhotonView attached to it.
What I initially do is grab a handle on all the children transforms and inside the OnPhotonSerializeView implementation, I loop through all these transforms and send over the stream:
This worked fine for gameobjects that had a smaller number of children, around 15-25. Now I'm using the same technique with gameobjects that contain 100+ children and I'm getting numerous
Any suggestions on how to handle syncing large numbers of children gameobjects or why these
What I initially do is grab a handle on all the children transforms and inside the OnPhotonSerializeView implementation, I loop through all these transforms and send over the stream:
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if (stream.isWriting) {
for (int i = 0; i < childrenTransforms.Length; i++) {
if (childrenTransforms[i] != null) {
stream.SendNext(childrenTransforms[i].localPosition);
stream.SendNext(childrenTransforms[i].localRotation);
stream.SendNext(childrenTransforms[i].localScale);
}
}
} else {
for (int i = 0; i < childrenTransforms.Length; i++) {
if (childrenTransforms[i] != null) {
childrenTransforms[i].localPosition = (Vector3)stream.ReceiveNext();
childrenTransforms[i].localRotation = (Quaternion)stream.ReceiveNext();
childrenTransforms[i].localScale = (Vector3)stream.ReceiveNext();
}
}
}
}
}
This worked fine for gameobjects that had a smaller number of children, around 15-25. Now I'm using the same technique with gameobjects that contain 100+ children and I'm getting numerous
InvalidCastExceptions
for clients that are reading from the stream (receiving updates). Any suggestions on how to handle syncing large numbers of children gameobjects or why these
InvalidCastExceptions
are showing up now that I have a longer list of children gameobjects? 0