PhotonView & RPC Best Practices

I'm relatively new to photon and network programming in general and have what I think is a fairly basic question about coding something one way or another.

In my multiplayer online shooter I have weapon pickups. If a player picks up a weapon by running over it, it will respawn after 20 seconds. What I'd like to know is what is the best approach to implementing this.

1. Put a photon view on every weapon pickup and then send an RPC when the pickup is available or not.
2. Have one managing Gameobject with a photon view on it, and this manager sends and receives the information about each weapon pickup.

In summary, I'm just curious if having multiple PhotonViews is better or worse than having 1 PhotonView managing multiple objects. Are PhotonViews expensive to add into the scene, even if their observed object isn't doing much?

Thanks!

ps - Is there any sort of "Best Practices" documentation available anywhere to read over? I've read all the documentation on Exit Games and the only other documentation I can see is the PDF + Examples on the asset store but it has poor reviews.

Comments

  • We don't have a best practice for "pickup" at the moment, I'm sorry. There are so many different use cases and situations. We would have a hard time covering each.
    But yes, we want to do more!

    About your questions:
    You should use RPC for pickup.
    The Master Client should keep track of all pickup items and spawn them.
    If they have specific places in the level, you can identify them without PhotonViews. Just index them automatically in the Editor, so you can reference them with some id at runtime.

    The Master Client should send a "spawn" RPC with one or many spawns and a timestamp. The timestamp is then used by the players in their RPC. The message would be: "I am picking up item X that spawned at time T". The Master Client checks the timestamp and if it is correct, the pickup is happening and a message "Pickup X at time T is OK. new timestamp: T2" is sent. The new timestamp T2 must be used for future pickups.
    If two players try to pickup the same item at the same time, one will end up first and the Master Client can clearly decide which one is successful.
    On the clients who picked up something, the pickup is not successful until the answer came.

    At the moment, this solution has a weak point: If the master leaves due to a lost connection, there won't be any master for a while. You won't get any pickups this way.

    There is a workaround for this but it doesn't work with PUN out of the box. You could send the pickup-message to everyone through the server. PUN will execute RPCs to all on the client immediately. If you send it through the server, any client can check the "pickup event" order and doesn't need a Master Client to decide.

    I will check how I can support this case in the next PUN release. In the mean time, you should use the Master Client described above.