Best approach for syncing child transforms

I have an object with multiple child objects that move in different ways that I want to keep synced. It seems to work to have PhotonView/PhotonTransformView components attached to the relevant child game objects.

As an example, think of a telescope where the base and lens pan, and the lens tilts, and the entire thing can be moved. I would have a PV/PTV components on the whole thing observing position, PV/PVT on the child base/lens object observing rotation, and a third PV/PTV on the child>child lens object observing its rotation.

Is there a better way? Thanks in advance - Dan

Comments

  • Hi @dyawitz,

    this would require a custom OnPhotonSerializeView solution you would have to implement. Using this new implementation you can synchronize all necessary values at once without having a PhotonTransformView component attached to each child game object. You just have to make sure that you are using the same order of the values when you are sending on one side and receiving on the other side.
  • OK, thanks Christian, this is very helpful.
  • @Christian_Simon ,

    I use OnPhotonSerializeView and loop through the root transform and all the children under my root transform.

    Using the OnPhotonSerializeView approach, if the root parent of these children updates it's transform does that mean all of it's children will have their transforms updated? How much data will be sent over the network? Will it only include the root transform or all the transforms of the children as well?
  • Using the OnPhotonSerializeView approach, if the root parent of these children updates it's transform does that mean all of it's children will have their transforms updated? How much data will be sent over the network? Will it only include the root transform or all the transforms of the children as well?


    This depends on what you write to the stream. By default the stream is empty and no data will be exchanged. If you only add the transform data (note: you can't serialize a Transform component by default) of the root object, only this data get sent. If you want to synchronize transform data of a child object, you have to add this manually by using stream.SendNext(child.someData);.