The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

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).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

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

Murky
2021-11-20 22:31:59

What about PhotonNetwork.Destroy(gameobject)

GetGoodIn
2021-12-10 05:22:42

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().ViewID;

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.

pilavyer
2022-10-12 08:30:26

GetGoodln, thank for your reply. I did exactly the same thing but still only master can destroy the objects... :(

Back to top