Issues with OnPhotonSerializeView

Hello!

I'll cut straight to the chase. I'm having a problem with OnPhotonSerializeView as it as I understand it, should be called a few times per second. However it doesn't seem to get called at all. I've got the IPunObservable as script type aswell as MonobehaviourPunCallbacks and it just won't work. I don't know what to do and I need this to work to be able to continue with my work.

Thanks in advance!

Comments

  • Does the GameObject you're syncing have a PhotonView, and is it identifying your script as a component to sync? Showing how you implemented OnPhotonSerializeView might help too

  • Hello!

    Should there be a photonview component on the same object as the script then? If that's the case that could well be the problem but I'll paste my entire script here aswell.

    Thanks for the response!

    using System.Collections;
    using System.Collections.Generic;
    
    using UnityEngine;
    using UnityEngine.UI;
    
    using Photon.Pun;
    using Photon.Realtime; 
    
    public class Chat : MonoBehaviourPunCallbacks, IPunObservable
    {
        #region public 
    
        public InputField chatField;
        public GameObject chatUI;
    
        #endregion
    
        #region private
    
        string myText;
        
    
        #endregion
    
        #region private methods
    
        void Update()
        {
            InputListener();
        }
    
        private void InputListener()
        {
            if (Input.GetKeyDown(KeyCode.Return) && myText.Length > 0)
            {
                
                chatField.text = "";
            }
    
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                CloseChat();
            }
        }
    
        public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            print("OnPhotonSerializeView");
            if (stream.IsWriting)
            {
                stream.SendNext(PhotonNetwork.NickName);
            }   
            else if (stream.IsReading) { string incomingText = (string)stream.ReceiveNext(); print(incomingText); }
        }
    
        #endregion
    
        #region public methods
    
        public void UpdateMessage() //Updates string as text is typed into the chatfield
        {
            myText = chatField.text; 
        }
    
        public void OpenChat()
        {
            chatUI.SetActive(true);
        }
    
        public void CloseChat()
        {
            chatUI.SetActive(false);
        }   
    
        #endregion
    }
    
  • Hello again!

    Found the problem.

    Apparently OnPhotonSerializeView isn't called if there aren't two players in a room and as I only tested with one player it didn't get called. Also seems I forgot a photonView component as you mentioned.

    Thanks for everything!