Search Unity

Third Party Photon Networking: Object observing itself won't read with OnPhotonSerializeView

Discussion in 'Multiplayer' started by Aaron_T, Apr 23, 2015.

  1. Aaron_T

    Aaron_T

    Joined:
    Sep 30, 2014
    Posts:
    123
    Hello, I'm having an issue that I can't seem to understand.

    I am trying to have any changes in a player's UI RectTransform show for other players on the network. The way that I have it set up, the scene's Canvas has my script (NetworkMeleeShipPickController) and a PhotonView that is observing its own NetworkMeleeShipPickController script. (See the following image.)



    Within my NetworkMeleeShipPickController script it has OnPhotonSerializeView that is set to write and read data about a playerID that I assigned the player and the anchor positions of the it's specific RectTransform (which is stored in an array). I have the log set to report when it is writing and when it is reading, and even with multiple players in the same room and scene the Console confirms that it is only writing, and never reading. (See code)

    • void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
    • if (stream.isWriting) { //We are sending info.
    • Debug.Log("WritingData");
    • stream.SendNext(myPlayerID);
    • stream.SendNext(selectorRect[myPlayerID].anchorMax);
    • stream.SendNext(selectorRect[myPlayerID].anchorMin);
    • }
    • else { //We are receiving info.
    • Debug.Log("ReadingData");
    • int receivedID = (int)stream.ReceiveNext();
    • selectorRect[receivedID].anchorMax = (Vector2)stream.ReceiveNext();
    • selectorRect[receivedID].anchorMin = (Vector2)stream.ReceiveNext();
    • }
    • }
     
    Last edited: Apr 23, 2015
  2. Aaron_T

    Aaron_T

    Joined:
    Sep 30, 2014
    Posts:
    123
    I figured it out, you must have multiple objects send data to each other.
     
  3. heartoffiremedia

    heartoffiremedia

    Joined:
    Nov 10, 2018
    Posts:
    1
    im still struggling with this problem, would you be willing to help me through this?