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

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.

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 practice to sync the position of NPCs

2021-10-23 09:32:06

Hi, sometimes I have over 40 characters(2 players + enemies) at the same time, that I synced correctly. Now I want to add more than 20 NPCs (as walking people in the scene) whose their position matters (because their role may change dynamically).

I was wondering if the PhotonTransformView is the right choice? Or maybe there is a better way to do it with less data usage(on the network).


[Deleted User]
2021-10-23 20:01:46

Hi, depending on how important the information is, you may want to change the data synchronize method. If all of the movement is important I would consider using "Reliable Delta Compressed". If not all the movement is important then I would consider using "Unreliable OnChange". Both of these types have different optimization techniques to use less data on the network.

Make sure the data types you are sending are also as small as possible. For example if you know your number never goes above 32767; do not use integer, use short. Bytes are the best thing you can send, but they are capped to 255 of course. Avoid sending custom types like Vector/Quaternion whenever possible, these have a few extra bytes of overhead on top of their usual 12-16 bytes worth of data.

In my opinion PhotonTransformView is the best thing you can use without making your own events. Your only other real option is RPCs, but those have much more data and performance overhead. They're also a lot more restrictive.

Generally if PhotonTransformView doesn't suffice for your game, you can always make your own system for transferring positional data, editing OnEvent in PhotonNetworkPart.cs will allow you to add that custom functionality.

2021-10-24 05:54:37

@MeepPun Thank you so much.

What's about the difference between "PhotonTransformView" and "PhotonTransformViewClassic"?

And One more question. As I mentioned just Being in the same position is enough for me.

Would you please tell me about using "Unreliable OnChange" and "Reliable Delta Compressed"?

[Deleted User]
2021-10-24 06:58:30


The regular PhotonTransformView is a much more simplified script. PhotonTransformViewClassic gives you more flexible options to configure. Such as teleportation over large distances.

The  "Unreliable OnChange" and "Reliable Delta Compressed" options are "Observe options". It's an option on your PhotonView component in the "Observables" section.

2021-10-24 16:23:29

Thanks alot @MeepPun

Back to top