Syncing Player Positions (Example)


I'm playing with the Demo Worker example. i've created my own prefab (Player.prefab) to replace the demo worker. The characters don't sync and end up flying around the map all over :s. Also the camera seems to keep rotating randomly.

Any ideas what is wrong :s.


  • Please follow this tutorial to setup your project and prefabs. ... 0Tutorials

    Maybe you forgot to add a PhotonView to the new prefab or your scripts try to control remote players as well as local ones.
    (can't check you project at the moment but those are common)
  • Hi,

    I have regone through the tutorial and done it all again. But some reason the characters arn't being synced :S. They just stay at the origin and if i add lerp to it then they just lerp between real position and origin :s.

  • I've done abit more research and i've found that the void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {} method isn't being called at all :S. I've attached a PhotonView and told it to observe the prefab.

    Any Ideas :s.
  • The PhotonView observes the prefab? It should observe a script on the prefab to call that script's OnPhotonSerializeView().
    Please drag & drop the script component to the PV and try again.
  • I get what you mean as currently it doesn't know what the script is to call that method.

    I've tried draging the C# script onto the observe method but it just won't work. If i drag the prefab onto observer then method won't get called. It says it has to be a transform i think.

    How do i do it :s. I think i'm missing something easy xD.

  • You need a MonoBehaviour. Add this to the GameObject where the PhotonView is. Then select the prefab and in it, select the script. Drag & drop the script component to the PhotonView.Observe field. It will accept the script if you selected is as being part of the game object.
  • I'm confused as to what you mean. Every script in Unity already has a monobehavior?. The network player has Photon.MonoBehavior. It sounds like your saying to add it in unity not script? but you can't do that can you?.
  • I mean: Your script has to be a part/component of the Game Object that also has the PhotonView. To "observe" said script, you have to drag&drop the script not from the project overview but from the game object's inspector.
  • Ah i finally understand what you ment :D. It works great now!. Thanks so much for help.
Sign In or Register to comment.