Using PhotonViews

I'm having trouble getting my PhotonView setup to work. I have verified that RPC's work in my program, and have verified that the overall server/client setup is working. I have also gotten the demo unity project included in the plugin to work.

I have attached a PhotonView object to my prefab, and dragged my Controller script which derives from Photon.MonoBehavior into the "Observe" property of the PhotonView object. I set the "ObserveOption" property to ReliableDataCompressed. Within my Controller script, I've implemented the OnPhotonSerializeNetwork() function. I've setup a Debug.Log() statement as my first statement within this function, and noticed that it is never outputed in Unity and basically that the OnPhotonSerializeNetwork() function is never called in my program. Again, I am able to successfully call RPC's, and am sure my program is able to communicate with the master server and basically that my server side setup is correct.

I've gotten my program to work successfully over the network when using Unity's normal NetworkView setup, but am unable to do it now with the PhotonView implementation.

Anyone have an idea what the problem might be? Thanks in advance.

Comments

  • I can't help right away (sorry) but: Is this still a problem, moo?
  • I am having a similar problem. The thing is that the game instance that created the room is the only one that is able to write to the stream. I am having one game instance that is a web game and the other is from the editor. The one that creates the room, if it changes, it writes to the stream and the other reads and gets updated. But the first won't update if the second has its value changed. Can anyone help? :roll:
  • Thats normal. Only the owner can write to it all others can only read. Writing without owner is only possible through RPC to send the data and make the owner write it in (authorative network model) cause RPCs don't care about owners.

    The owner is the one that originally created it, if it was within the scene then its normally the master client.
    For PlayerObjects you want to use PhotonNetwork.Instantiate so the client can instantiate his avatar or whatever and get a view he owns for writing
  • Thank you Dremora... but.. Are you sure? The info at the pdf states the following:

    A PhotonView can be set to observe a MonoBehaviour. In this case, the script‟s OnPhotonSerializeView method will be called. This method is called for writing an object‟s state and for reading it, depending on whether the script is controlled by the local player.
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     { 
    if (stream.isWriting) { //We own this player: send the others our data stream.SendNext((int)controllerScript._characterState);          stream.SendNext(transform.position); stream.SendNext(transform.rotation); 
    } 
    else 
    { //Network player, receive data controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
    correctPlayerPos = (Vector3)stream.ReceiveNext();
    correctPlayerRot = (Quaternion)stream.ReceiveNext();
     } 
    }
    

    There isn't a single word clarifying that only the master client can write to the stream.
  • If it does what one would intuitively assume, work like Unity networking, then yes, it would limit the write to only the owner.

    There is also a reason for doing that and thats if anybody can write, how do you resolve the situation where 2 write at the same time? With delta its not possible to resolve that at all anymore, you get an undefined state and thats about the very last thing you want to see happen. Only RPCs can be sent in both directions as functions are called there explicitely at a remote place which ensures that nothing can fuck up, there is no 'delta code' etc as they are to send parameters to a remote place for remote function execution thats meant to handle its own transactional correctness

    I would have to check if PUN does that but I would take it for granted that it does.

    For that reason it technically shouldn't be possible to write from anyone but the owner cause the owner system normally, in any other place, is meant to be an 'Observer pattern' if that tells you something. So basically the observer 'says' something and anybody interested in it listens to it. But nobody else can say anything on the channel as nobody would listen to him at all. Oberserver pattern is a 1 way channel from the 1 information sending entity to an unlimited number of information receiving entities.
  • Ok. I thank you very much for your help. :)
Sign In or Register to comment.