Instantiating an object for only specific player(s)?

Options
How can I instantiate an object but only for specific players? Something like:

PhotonNetwork.Instantiate("myObject", targetActors: new []{photonPlayer.ID, otherPhotonPlayer.ID});

Comments

  • Hi @rafael_at_jags,

    sorry for the late response.

    You can do this by using interest groups. When instantiating an object using PhotonNetwork.Instantiate(...); you can set the last parameters to something else than 0. In PUN, 0 is the default group and each client is automatically subscribed to it in order to receive all events and messages published to this specific group.

    If you want to use this, you can e.g. call PhotonNetwork.Instantiate(..., 1);, means that the Instantiation call is only forwarded to clients subscribed to group 1 in this case.

    By default none of the clients will see this instantiation so you need to subscribe to the group first. you can do this by using the following code snippet:
    PhotonNetwork.networkingPeer.SetReceivingEnabled(1, true);
    PhotonNetwork.networkingPeer.SetSendingEnabled(1, true);