4
\$\begingroup\$

I have a button on my main menu that creates and has the player join a random room. After the client joins this room, I change the scene to the game (main) scene in the OnJoinedRoom method. This works well, until I use the RPC call with buffers.

There are 5 spawn points in the game scene, and every time a player joins the room, they occupy a spawn point, so no-one else can spawn at that point. So, I have list of spawn points in my code, and every time a player joins, it randomly picks a point from that list and "removes" it from the list. It does this via RPC call, so if a player joins the game late, it removes that point, too.

There is a problem with that RPC's buffer because of the "scene change". After OnJoinedRoom, the RPC buffers are called only when the player joins the room, and before the scene change. Because the scene hasn't changed yet, it has trouble finding the buffered photonview, and it throw outs an error. It doesn't update the list.

Can I delay the buffer calls, is there a better way to change my scene while joining a room?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

A more reliable and efficient method of syncing new players is delegating this task to another player. Since Photon's servers aren't authoritative, this is the next best option to catch someone up.

One method is to send an RPC to the master client telling it to catch you up on the game state. The master client then sends you a stream of data giving you information about everything you need. This gives you full control over the replication on new player.

Alternatively, you could buffer received buffered RPCs and process them once your scene is loaded. This is probably easier since you won't have to have the master client gather everyone's information but keep in mind that every single buffered RPC will get sent to the new player. This means if you send a buffered RPC every time a door opens/closes, the new player will get all those RPCs even if all but 1 are outdated and useless.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for the helpful answer. But i am not sure how should i implenet those methods. How do i "ask to catch up" by RPC call? Doesn't RPC stand for, "trigger that function on another machine"? Secondly, i also don't know, how to buffer, a buffered RPC. That solution seems easier to do, but i don't know how to do it. -Thank you \$\endgroup\$
    – OldBerkay
    Commented May 22, 2015 at 18:36
  • \$\begingroup\$ I think it's something like PhotonNetwork.RPC ("SyncMe", PhotonTargets.Master, (byte)0); . In response, the master client sends back PhotonNetwork.RPC ("SyncGive", PlayerToSync, SerializedData); Serialized data consists of all entities' position and identification. \$\endgroup\$
    – JPtheK9
    Commented May 22, 2015 at 18:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .