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.

Best approach for syncing child transforms

dyawitz
2018-04-12 20:16:40

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

[Deleted User]
2018-04-17 09:03:35

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.

dyawitz
2018-04-17 18:06:48

OK, thanks Christian, this is very helpful.

talothman
2018-08-01 18:02:03

@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?

[Deleted User]
2018-08-02 08:45:26

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);.

Back to top