Use onserialise view instead of rpc

Options
Hello i have a small card game based on rpc. after some time says that are too much rpc and in this way the game just crash. Is it possible using onserialise view and if yes how can get the updated values in other players?

Comments

  • Tobias
    Options
    Too many RPCs? Can you copy and paste the exact error?
  • Eduard
    Options
    It is not exactly an error but a debug log from photon saying "QueueIncomingReliableWarning. This client buffers many incoming messages. This is OK temporarily. With lots of these warnings, check if you send too much or execute messages too slow. "
    I have some variables that should be the same in all players. Here are two options
    private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting){ stream.SendNext(lastmin); stream.SendNext(lastbomb); stream.SendNext(passnumber); stream.SendNext(maxvalueinturn); stream.SendNext(cardsinturn); stream.SendNext(lastsimiliarvalue); stream.SendNext(firstplayer); stream.SendNext(angle); } else { lastmin=(int)stream.ReceiveNext(); lastbomb=(int)stream.ReceiveNext(); passnumber=(int)stream.ReceiveNext(); maxvalueinturn=(int)stream.ReceiveNext(); cardsinturn=(int)stream.ReceiveNext(); lastsimiliarvalue=(int)stream.ReceiveNext(); firstplayer=(int)stream.ReceiveNext(); angle=(float)stream.ReceiveNext(); } }
    and the two option
    public void updatepropertiescv(int lmin, int lbom, int pass, int mxint,int cardinturn, int lastsim, int fplayer, float ang ){ lastmin=lmin; lastbomb=lbom; passnumber=pass; maxvalueinturn=mxint; cardsinturn=cardinturn; lastsimiliarvalue=lastsim; firstplayer=fplayer; angle=ang; }
    which method is best to keep these values updated among players?
  • Tobias
    Options
    I don't see how the second syncs the values at all.
    Check out this page: https://doc.photonengine.com/en/pun/current/tutorials/synchronization-and-state
  • Eduard
    Options
    Yes when a player changes the values a rpc is called with parameters thast contains the updated values.
    this works well but after some time it gives the warning that are too much messages.
    Would you think that if I convert these variables into an object is more optimised and in this way dont show warnings that there are too much messages.
    when I use the first option this message doesn't show but I need rpc not onserialiseview.
  • Eduard
    Options
    I am using the second option but I created an serialized object in bytes and pas throught rpc but it gives nullreference. Here is the class and function that initialise class variables
    public int lastmin { get; set; } public int lastbomb { get; set; } public int passnumber{ get; set; } public int maxvalueinturn { get; set; } public int cardsinturn { get; set; } public int lastsimiliarvalue { get; set; } public int firstplayer { get; set; } public float angle{ get; set; } public int playerid { get; set; } public string playername { get; set; } public int cardsin{ get; set; }
    function that initialise class
    public void updateinfo(int lmin, int lbom, int pass, int mxint,int cardinturn, int lastsim, int fplayer, float ang, int playid,string namepl,int numberofcard){ o1=new playerupdates(){ lastmin=lmin, lastbomb=lbom, passnumber=pass, maxvalueinturn=mxint, cardsinturn=cardinturn, lastsimiliarvalue=lastsim, firstplayer=fplayer, angle=ang, playerid=playid, playername=namepl, cardsin=numberofcard}; }
  • Tobias
    Options
    Have a look at the Nullreference Exception. It will tell you the line where something is null.
    I can't see why it is.
  • Eduard
    Options
    One guy at stackoverflow help me to solve that but now I am having nullreference in deserilization. I will post the answer If I dont forget. Thank you for help
    [PunRPC] public void updatecardsintable(byte [] crdstotable){ playerupdates o2 = selem.DeserializeObject<playerupdates>(crdstotable);//error null lastmin=o2.lastmin; lastbomb=o2.lastbomb; passnumber=o2.passnumber; maxvalueinturn=o2.maxvalueinturn; cardsinturn=o2.cardsinturn; lastsimiliarvalue=o2.lastsimiliarvalue; firstplayer=o2.firstplayer; angle=o2.angle; playerid=o2.playerid; playername=o2.playername; cardsin=o2.cardsin; }
    playerupdates o2 = selem.DeserializeObject(crdstotable);//error null
  • Eduard
    Options
    I have done some tests and ser/des works well but in below case I cant get it to work
  • Tobias
    Options
    There is no below?!
  • Eduard
    Options
    after a cleanup it works well. But I want to ask you something as using rpc in my game is imposible. I dont know but after I get some mesages in console that there are too messages rpc mesagess are blocked., and my game do not work as expected. To be clear with you I wil take player position . When one player sends his position, I want that other players store his position . and thank you for assistance.
  • Tobias
    Options
    Position updates are better sent as unreliable and you can't do that with RPCs. You also have to re-build the logic to send position updates in a (more or less) fixed frequency.
    You should update player positions with OnPhotonSerializeView(), not with RPCs.
    https://doc.photonengine.com/en/pun/current/tutorials/synchronization-and-state

    If you have a warning about too many sent messages, find out if you have to send all of those and reduce the number.
  • Eduard
    Options
    I solve the problem using of too many messages using protobuf. thanks for your help