Photon Unity Networking 2 2.30

Public Member Functions | Public Attributes | List of all members
OnClickDestroy Class Reference

Destroys the networked GameObject either by PhotonNetwork.Destroy or by sending an RPC which calls Object.Destroy(). More...

Inherits MonoBehaviourPun, and IPointerClickHandler.

Public Member Functions

IEnumerator DestroyRpc ()
 

Public Attributes

PointerEventData.InputButton Button
 
KeyCode ModifierKey
 
bool DestroyByRpc
 

Additional Inherited Members

- Properties inherited from MonoBehaviourPun
PhotonView photonView [get]
 A cached reference to a PhotonView on this GameObject. More...
 

Detailed Description

Destroys the networked GameObject either by PhotonNetwork.Destroy or by sending an RPC which calls Object.Destroy().

Using an RPC to Destroy a GameObject is typically a bad idea. It allows any player to Destroy a GameObject and may cause errors.

A client has to clean up the server's event-cache, which contains events for Instantiate and buffered RPCs related to the GO.

A buffered RPC gets cleaned up when the sending player leaves the room, so players joining later won't get those buffered RPCs. This in turn, may mean they don't destroy the GO due to coming later.

Vice versa, a GameObject Instantiate might get cleaned up when the creating player leaves a room. This way, the GameObject that a RPC targets might become lost.

It makes sense to test those cases. Many are not breaking errors and you just have to be aware of them.

Gets OnClick() calls by Unity's IPointerClickHandler. Needs a PhysicsRaycaster on the camera. See: https://docs.unity3d.com/ScriptReference/EventSystems.IPointerClickHandler.html