Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Third Party Not clear what OnPhotonSerializeView does

Discussion in 'Multiplayer' started by mirzahat, Sep 1, 2015.

  1. mirzahat

    mirzahat

    Joined:
    Dec 21, 2014
    Posts:
    53
    Hallo

    in all tutorials I see that an object sends data over the network and receives the data
    for sync in the same method:

    Code (csharp):
    1.  
    2. void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){
    3.         if (stream.isWriting) {
    4.             stream.SendNext (transform.position);
    5.             stream.SendNext (transform.rotation);
    6.         } else {
    7.            
    8.             Debug.Log("never gets called ");
    9.            
    10.             //never gets called...
    11.  
    12.             transform.position = (Vector3)stream.ReceiveNext ();
    13.             transform.rotation = (Quaternion)stream.ReceiveNext ();
    14.  
    15.         }
    16.     }
    17.  
    But when I test my code, the lower part, where the data gets received, is never executed!

    I never see the logs. But the object is SYNCHED because it is set in the inspector:

    https://www.dropbox.com/s/kuwm262ws534b6i/x.jpg?dl=0

    But the problem is that the object is not interpolated so it looks kind of funny.

    So, I need to know how can I make the upper method to work so I can do some interpolation stuff.

    Mirza
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    Please do the Marco Polo Tutorial. It will help you get to the "else" part of this.
    If you did it like in the tutorial, it should work. If you're then still stuck, let us know.
     
  3. mirzahat

    mirzahat

    Joined:
    Dec 21, 2014
    Posts:
    53
    I did it and it helped me a lot. I understand the concepts.

    The problem is that it once worked...now it is not.

    The stream is only written bt one client, and it does not receive it at all!

    Mirza
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    One client writes, the others in the same room receive.
    Make sure there's someone else in the same room. Make sure you dragged the script into the "observed" list on the prefab's PhotonView.