Get Player Disconnected GameObject (PhotonView)
Options
Hi !
I use OnPhotonPlayerDisconnected(PhotonPlayer player).
I want to get the gameobject that the player instantiated before he disconnected and leave the room.
How can i do it?
Thanks.
I use OnPhotonPlayerDisconnected(PhotonPlayer player).
I want to get the gameobject that the player instantiated before he disconnected and leave the room.
How can i do it?
Thanks.
0
Comments
-
Hi @liorium,
I guess you are looking for something like this:public void OnPhotonPlayerDisconnected(PhotonPlayer otherPlayer) { foreach (PhotonView pv in FindObjectsOfType<PhotonView>()) { if (pv.ownerId == otherPlayer.ID) { // if the client has multiple objects instantiated you need a second condition (e.g. Tag) } } }
1 -
I tried above and it didn't work. I put it at the top of the "public override void OnPlayerLeftRoom(Player player)" (as I assume is the equivalent in PUN2) and I got every other player instance, but the one who disconnected. Or let me clarify, using above returned me null, setting pv.Owner != null, returned me every other player than the disconnected player0
-
In PUN2 it is
public override void OnPlayerLeftRoom(Player otherPlayer) { foreach (PhotonView pv in FindObjectsOfType<PhotonView>()) { if (pv.OwnerActorNr == otherPlayer.ActorNumber) { // if the client has multiple objects instantiated you need a second condition (e.g. Tag) } } }
0 -
Thanks alot it helped so much!
Here is the example from me;foreach (inventory inventory in FindObjectsOfType<inventory>()) { if (inventory.pv.OwnerActorNr == otherPlayer.ActorNumber) //Get disconnected players inventory { for (int i = inventory.itemList.Count - 1; i >= 0; i--) //Get all inventory items { if (inventory.itemList[i] != inventory.itemList[0]) //expect empty inventory item (which is 0) { inventory.itemList[i].gameObject.SetActive(true); inventory.itemList[i].gameObject.transform.parent = null; inventory.itemList[i].colliderItem.enabled = true; inventory.itemList[i].rigidbodyItem.isKinematic = false; inventory.itemList[i].pv.TransferOwnership(0); } } } }
Im finding the disconnected players inventory and dropping down each item they had.0