Syncing Large Number of Children Transform using OnPhotonSerializeView
Options
I'm attempting to achieve two main objectives:
- Sync transform state of root gameobject with many (200+) children
- Be able to add and delete children gameobjects from under the root gameobject and sync their states
OnPhotonSerializeView
that does the following:
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(); } } } } }Three main questions:
- Does this seem like the right approach to handle syncing of large gameobject transform hierarchies?
- If the root gameobjects transform changes, does that send update message for all of it's children?
- This currently works fine with small transform hierarchies but I've tested with very large ones and I get numerous InvalidCastExceptions on the clients listening for updates and the connection drops.
0
This discussion has been closed.