How can other players destroy room objects?
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
How can other players destroy room objects?
MMSix
2021-11-18 16:55:02
I am having a problem getting other players that are not the master to destroy enemies. These enemies are instantiated as room objects by the master client. The master client can destroy these enemies when they shoot them with a projectile or when the enemy collides with the master client. When the other players shoot the enemy or the enemy collides with them, the enemy is not destroyed. The player is damaged however. I have tried using photonView.IsMine as well as PhotonNetwork.IsMasterClient. Any ideas?
Here is the code snippet of the collision detection where the enemy should be deleted. This script is attached to the enemy. Debug logs are called, but enemy is not destroyed when other players collide with or shoot the enemy.
Update: The collision is happening on the client side so the client can not destroy the room objects. A simple RPC call to only the Master Client, that will destroy this game object, fixed the problem! Idk if there is a better wat, but a RPC call worked, for anyone else with this problem.
Comments
What about PhotonNetwork.Destroy(gameobject)
I legit spend way too long on this. Wish there was a straight to the point tut on destroying stuff and the most common stuff. But for people who need this, what I did was:
I used a Raycast when pressing E - i did:
if (hit.collider.gameObject.tag == "Item")
{
int viewID = hit.collider.GetComponent
photonView.RPC("DestroyFoodItem", RpcTarget.MasterClient, viewID);
}
And then the Function:
[PunRPC]
public void DestroyFoodItem(int viewID)
{
PhotonNetwork.Destroy(PhotonView.Find(viewID).gameObject);
}
And it finally worked, without errors. Client can destroy gameobjects and so can the master.
GetGoodln, thank for your reply. I did exactly the same thing but still only master can destroy the objects... :(
Back to top