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?
0
Comments
-
Too many RPCs? Can you copy and paste the exact error?0
-
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 optionsprivate 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 optionpublic 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?0 -
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-state0 -
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.0 -
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 classpublic 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}; }
0 -
Have a look at the Nullreference Exception. It will tell you the line where something is null.
I can't see why it is.0 -
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 null0 -
I have done some tests and ser/des works well but in below case I cant get it to work0
-
There is no below?!0
-
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.0
-
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.0 -
I solve the problem using of too many messages using protobuf. thanks for your help0