Sending player some initial data with OnPlayerEnteredRoom - does it work for subsequent scenes?

I'm currently sending a newly joining client some initial data about an object by sending him an RPC in OnPlayerEnteredRoom, but I was wondering: if the players change scenes, and the MasterClient creates a new object before the other player has finished loading, he'll need that initial data again for the new object in the new scene (but obviously OnPlayerEnteredRoom will not fire again.

What callback should I use in this case? Is there some Photon callback for when a client finishes loading the level? Or does the host wait for all clients to load a network loaded level before allowing the master client to act/play?

Comments

  • Hi @legend411,

    if the initial data isn't changed (constant), you can use the Instantiation Data to share it. When calling PhotonNetwork.Instantiate, there is an optional fifth parameter which can be used for that. Accessing the data works by using the object's PhotonView component: object[] instantiationData = photonView.InstantiationData;. It works with Scene Objects, too.

    What callback should I use in this case? Is there some Photon callback for when a client finishes loading the level?


    There isn't such a callback. You would have to implement a similar logic on your own. This could be done by using the Custom Player Properties for example.
  • Hi @legend411,

    if the initial data isn't changed (constant), you can use the Instantiation Data to share it. When calling PhotonNetwork.Instantiate, there is an optional fifth parameter which can be used for that. Accessing the data works by using the object's PhotonView component: object[] instantiationData = photonView.InstantiationData;. It works with Scene Objects, too.

    What callback should I use in this case? Is there some Photon callback for when a client finishes loading the level?


    There isn't such a callback. You would have to implement a similar logic on your own. This could be done by using the Custom Player Properties for example.
    Nah I don't think instantiation data will cut it, its not that kind of initial data, its data that changes... for instance, my enemy AI have a "target player" variable that needs to be synced, I currently sync it with RPCs, but obviously that does nothing for late joining players. I could Send late joining players an RPC in OnPlayerEnteredRoom, but that doesn't help the weird edge case where the game might've network changed scenes and an AI acquired a target before a player loads (a late loading player?)

    Using serialization doesn't really help either because it needs to be reliable, and my AI already have unreliable photon views.

    The AI is not a player either, just a networked object owned by the master client, so I don't see custom player properties helping much.

  • So in this case I guess using the OnPlayerEnteredRoom callback and let the MasterClient inform the new client might be the best option. The other synchronization can be done with RPCs, too.

    The other option would be using a custom OnPhotonSerializeView solution, but I think that you have already excluded this option.