Getting Error With RPCs

Hi guys,
This is my first post here on the forums! So the error I am getting happens when I try to send a RPC. The error is as follows:
"The observed monobehaviour (_Scripts) of this Photon View does not implement OnPhotonSerialize()!
So how does one go about implementing OnPhotonSerialize? Thanks for your help!

Comments

  • I may be wrong, but you can try one of the following:
    [code2=csharp]public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
    }[/code2]
    [code2=csharp]public void OnPhotonSerialize(PhotonStream stream, PhotonMessageInfo info)
    {
    }[/code2]
    I'm not sure if the second one will work, but its telling you OnPhotonSerialize(), not OnPhotonSerializeView(), but when I keep the top one in my code, I don't get that error so the top one should work. I don't know if you need to fill the parameters like I did. Just stick one of these methods anywhere in your code.
  • Huh I did that and it doesn't seem to work...Maybe I need to add something else but here is my code if it helps:
    [code2=csharp]using UnityEngine;
    using System.Collections;

    public class NetworkManager : MonoBehaviour
    {
    public Camera StandbyCamera;
    public static float GameTime = 500;
    public GameObject myPlayerGO;
    GameObject SnowBallInst;
    PhotonView photonView;
    bool PlayerSpawned = false;
    public bool OfflineMode = false;
    bool TimerSetoff = false;
    bool host = false;

    void Start ()
    {
    photonView = PhotonView.Get(this);
    Debug.Log(photonView.ToString());
    GameTime = 500;
    Connect ();
    }
    void Connect()
    {
    if(OfflineMode)
    {
    PhotonNetwork.offlineMode = true;
    OnJoinedLobby();
    }
    else
    {
    PhotonNetwork.ConnectUsingSettings("1.0.0");
    }
    }
    void OnGUI()
    {
    GUI.BeginGroup (new Rect (1 ,1 , 150, 150));
    GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
    GUILayout.Label("Time Left: " + GameTime.ToString());
    GUI.EndGroup ();
    }
    public void OnPhotonSerialize(PhotonStream stream, PhotonMessageInfo info)
    {

    }
    void OnJoinedLobby()
    {
    PhotonNetwork.JoinRandomRoom();
    }
    void OnPhotonRandomJoinFailed()
    {
    PhotonNetwork.CreateRoom(null);
    TimerSetoff = true;
    host = true;
    }
    void OnJoinedRoom()
    {
    SpawnMyPlayer();
    photonView.RPC("PlayerJoined", PhotonTargets.MasterClient);
    }
    void SpawnMyPlayer()
    {
    int Random1 = (Random.Range(0,1));
    Vector3 RandomSpawnPos = new Vector3(0,5,0);
    myPlayerGO = (GameObject)PhotonNetwork.Instantiate("First Person Controller", RandomSpawnPos, new Quaternion(0,0,0,0), 0);
    ((MonoBehaviour)myPlayerGO.GetComponent("FPSInputController")).enabled = true;
    ((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
    ((MonoBehaviour)myPlayerGO.GetComponent("PlayerLink")).enabled = true;
    if(Random1 == 0)
    {
    myPlayerGO.transform.tag = "RedTeam";
    ScoreTracker.team = 0;
    }
    else
    {
    myPlayerGO.transform.tag = "BlueTeam";
    ScoreTracker.team = 1;
    }
    myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);
    StandbyCamera.enabled = false;
    PlayerSpawned = true;
    }
    [RPC]
    void TimerControler(float GameTime1)
    {
    if(!TimerSetoff)
    {
    GameTime = GameTime1;
    TimerSetoff = true;
    }
    }
    [RPC]
    void PlayerJoined()
    {
    if(host)
    {
    photonView.RPC("TimerControler", PhotonTargets.Others, GameTime);
    }
    }
    void Update()
    {
    if(TimerSetoff)
    {
    GameTime-= Time.deltaTime;
    }
    }
    }[/code2]
    All I really am trying to do is learn RPCs through a master client game time. This is my first photon project so any mistakes you see, feel free to correct! Thanks again.
  • A couple things:
    1. Change OnPhotonSerialize() to OnPhotonSerializeView() because I guess OnPhotonSerialize() isn't real.
    2. If you want to use photon views I'm pretty sure you have to change MonoBehaviour to Photon.MonoBehaviour at the 4th line of your code.
  • I will have to fix that error message. It should be "OnPhotonSerializeView", just like in the demos.
    http://doc.exitgames.com/photon-cloud/M ... o_Tutorial

    menachemt: Thanks for helping! You don't need to use Photon.MonoBehaviour. It's just easier to access the PhotonView on the GameObject when using it. The callbacks get called also on plain MonoBehaviours.
  • OK, I have done all of that but I still get the error. The interesting thing is, if I hit un-pause after the error on the master-client both clients continue to run flawlessly and do exactly as they should with the timer. So.... could I try a try catch?
  • This is not an exception. It's an error that is being logged. You can't try-catch that.
    You will have to check all PhotonViews in the project and which scripts they observe. Those scripts must implement OnPhotonSerializeView correctly or you won't get rid of this issue.
  • Thank you so much! I haven't been able to fix this error for for ever but you had the fix, Thanks!
  • LeeroyJenks
    edited February 2014
    Hey,
    I'm having the same problem as wyler and, maybe, I can give a little more insight into what's causing the problem.

    I am experiencing the problem when using an PhotonView RPC to PhotonTargets.AllBuffered. Nothing else causes the error. I get the Error when any person connects to the scene and needs the buffered information. I'll post the main code part of what's going on so you can give it a check. Everything seems to be correct and it works fine when PhotonTargets.All is called instead (of course I don't get the buffered information). Any help would be greatly appreciated. Thanks!

    Additional Info. PhotonTargets.All works fine without OnPhotonSerializeView. The only thing i'm really having a problem with is the PhotonTargets.AllBuffered, yet I really need it for this part of my game.

    Some even further detail. On the other end I get the error:
    PhotonView with ID 1 has no method "AddTeam_RPC" marked with [RPC](C#) or @RPC(JS) property! Args:String
    As you can see, rpc is attached so, could it be that buffered does not stay as string, float, etc? do I need to convert these arguments when I load?

    [code2=csharp]public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){

    }

    void AddTeam1(string p){
    gameObject.GetComponent<PhotonView>().RPC("AddTeam1_RPC", PhotonTargets.AllBuffered, p);
    }

    [RPC]
    void AddTeam1_RPC(string p){
    team1.Add(p);
    }

    void AddTeam2(string p){
    gameObject.GetComponent<PhotonView>().RPC("AddTeam2_RPC", PhotonTargets.AllBuffered, p);
    }

    [RPC]
    void AddTeam2_RPC(string p){
    team2.Add(p);
    }

    void RemoveTeam1(string p){
    gameObject.GetComponent<PhotonView>().RPC("RemoveTeam1_RPC", PhotonTargets.AllBuffered, p);
    }

    [RPC]
    void RemoveTeam1_RPC(string p){
    team1.Remove(p);
    }

    void RemoveTeam2(string p){
    gameObject.GetComponent<PhotonView>().RPC("RemoveTeam2_RPC", PhotonTargets.AllBuffered, p);
    }

    [RPC]
    void RemoveTeam2_RPC(string p){
    team2.Remove(p);
    }

    void Team1Color(float r, float g, float b){
    gameObject.GetComponent<PhotonView>().RPC("Team1Color_RPC", PhotonTargets.AllBuffered, r, g, b);
    }

    [RPC]
    void Team1Color_RPC(float r, float g, float b){
    team1Color = new Color (r, g, b);
    }

    void Team2Color(float r, float g, float b){
    gameObject.GetComponent<PhotonView>().RPC("Team2Color_RPC", PhotonTargets.AllBuffered, r, g, b);
    }

    [RPC]
    void Team2Color_RPC(float r, float g, float b){
    team2Color = new Color( r, g, b);
    }[/code2]
  • Make sure you have the on serialize method in all your scripts! When I got the error I just threw the method into all the scripts in the scene and it fixed the error.
  • wyler0 wrote:
    Make sure you have the on serialize method in all your scripts! When I got the error I just threw the method into all the scripts in the scene and it fixed the error.

    Tried that. Even with it, it still gives me the "does not implement OnSerialize" and the other end gives me the error I mentioned previously. Kind of stumped.
  • If a PhotonView observes a MonoBehaviour, said script has to implement OnPhotonSerializeView. Otherwise, the error you report cannot happen.
    Maybe your prefab setup is not ok or something but I don't see any link between AllBuffered and OnPhotonSerializeView really.
    In all scenes that you use, check all PhotonViews if they observe a script. If they do, implement OnPhotonSerializeView accordingly. In worst case: remove and re-add the PhotonView and save the scene.

    RPCs can be called from ANY component on the GO - it doesn't have to be an observed script.

    If you can't solve it, please package a repro project (small), upload it somewhere and mail us the link and how we produce the issue to check it.
    At the moment, I'm lost, sorry.
  • Tobias wrote:
    If a PhotonView observes a MonoBehaviour, said script has to implement OnPhotonSerializeView. Otherwise, the error you report cannot happen.
    Maybe your prefab setup is not ok or something but I don't see any link between AllBuffered and OnPhotonSerializeView really.
    In all scenes that you use, check all PhotonViews if they observe a script. If they do, implement OnPhotonSerializeView accordingly. In worst case: remove and re-add the PhotonView and save the scene.

    RPCs can be called from ANY component on the GO - it doesn't have to be an observed script.

    If you can't solve it, please package a repro project (small), upload it somewhere and mail us the link and how we produce the issue to check it.
    At the moment, I'm lost, sorry.

    Thank you so much for being so adamant about helping others. I really appreciate that we can have a direct connection with someone for help.
    That being said, I figured out the problem but am not too sure how to fix it. I read through the documentation again and came across the "Timing for RPCs" section.
    This is what's going on. I'll try to write it here before I bother you with a package.

    Player 1 creates a game, which loads a different scene (scene1). In scene1, player1 selects a team and a color, which are messages that are sent to all buffered.
    Meanwhile, player2 is still in scene0 and just found the game to connect to. When he clicks on the game, he loads up scene1 and is then encountered with an error and cannot see player1 in any team or his color.

    So I see that player2 is receiving messages for something he does not have yet. Then, when he joins scene1, the messages were discarded and he gets an error. I noticed in the documentation that it talks about pausing RPC messages, but am not sure how to apply that to my specific scenario.

    I will be working on it today trying to see if I can fix it on my own. Any help would be greatly appreciated and if I figure it out I'll come back and finish this off.

    Thanks again!

  • I will be working on it today trying to see if I can fix it on my own. Any help would be greatly appreciated and if I figure it out I'll come back and finish this off.

    Thanks again!

    Got it!
    The problem was that, as soon as player2 joined the room, he would receive all of the buffered messages, however, he had not yet loaded the new scene.

    If anyone ever has this problem here is the fix:

    PhotonNetwork.isMessageQueueRunning = false;

    as soon as you join the room (but after all of the information you need to be sent to join the room is completed, therefore OnJoinedRoom).

    PhotonNetwork.isMessageQueueRunning = true;

    once the new scene is loaded, allowing the player to receive all buffered messages.

    thanks Tobias for the great help and wyler0 for starting a conversation I needed.
  • Good to read you could solve your issue and thanks for posting the solution!
    Hope you can now make good progress.