Destroy instantiated Object as non master client

hey

i have an Object " M4A1 " and i instantiate it with :
void Start () {
        GameObject m4 = (GameObject)PhotonNetwork.Instantiate("M4A1 PickUp", new Vector3(0,0,0), new Quaternion(0,0,0,0), 0);
    }

when i pick it up i wanna destroy the Object:
[RPC]
    void OnTriggerStay(Collider other) {
       
        if(Input.GetButtonDown("Interaction")){
            TakeItem ();
            DestroyOnNetwork (other);
        }
    }

the destroyonnetwork function:
void DestroyOnNetwork(Collider other) {
 
        PhotonNetwork.Destroy(other.gameObject);
 
        if( GetComponent<PhotonView>().instantiationId==0 ) {
            Destroy(other.gameObject);
        }
        else {
            if( GetComponent<PhotonView>().isMine ) {
                PhotonNetwork.Destroy(other.gameObject);
            }
        }
    }

My Problem is that i can only destroy the object with the master client.

other clients get the error:

Failed to 'network-remove' GameObject. Client is neither owner nor masterClient taking over for owner who left: View (0)1002 on M4A1 PickUp(Clone)

how can i destroy the object if iam not the master client ? i thought the [RPC] over void OnTriggerStay(Collider other) would do that part for me ?

Comments

  • I just had a quick look and I can't see where are you calling photonView.RPC? That required.

    How is this RPC being called on the other clients?
  • where do i have to use that photonview.rpc ?
  • You want to check isMine before you call PhotonNetwork.Destroy(other.gameObject);
    PhotonNetwork.Destroy() is synced by PUN. You don't have to do this again. But only the controller of the GO can destroy it (you can't destroy someone else's character, e.g.).

    You can use photonview.RPC() on any script that's on a GameObject that also has a PhotonView, so it's networked.
    Do the Tutorial:
    http://doc.exitgames.com/en/pun/current ... marco-polo
  • okay i did the tutorial but i couldnt use the information to solve my problem :/

    i changed my code to this:
    void OnTriggerStay(Collider other) {
    
    		if(Input.GetButtonDown("Interaction")){
    			TakeItem ();
    			GetComponent<PhotonView>().RPC ("DestroyOnNetwork", PhotonTargets.AllBuffered, other);
    		}
    }
    

    and
    [RPC]
    	public void DestroyOnNetwork(Collider other) {
    		
    		if( GetComponent<PhotonView>().instantiationId==0 ) {
    			Destroy(other.gameObject);
    		}
    		else {
    			if(GetComponent<PhotonView>().isMine) {
    				PhotonNetwork.Destroy(other.gameObject);
    			}
    		}
    }
    

    but know i cant even destroy the object with the master client anymore because of this error:

    PhotonView with ID 1001 has no method "DestroyOnNetwork" that takes 1 argument(s): BoxCollider



    This script is attached to the Player,
    the Player and the M4 Object have the PhotonView Component so why does it say that there is no method "destroyonnetwork" ?!?! its right there !!!!
  • If you want to send an RPC to do something with any GameObject, then find that GameObject and it's PhotonView and call the RPC on it. The RPC will only be executed on that GameObject.
    You should not send the collider. The colliders are not networked and each client has another collider instance.
  • Hey thx for the help, i had a little progress now.

    i changed the code to this:
    void OnTriggerStay(Collider other) {
    
    		if(Input.GetButtonDown("Interaction"))
    		{
    			TakeItem ();
    			pvID = other.gameObject.GetComponent<PhotonView>().viewID;
    			GetComponent<PhotonView>().RPC ("DestroyOnNetwork", PhotonTargets.AllBuffered, pvID);
    		}
    	}
    
    [RPC]
    	public void DestroyOnNetwork(int pvID) {
    		PhotonNetwork.Destroy(PhotonView.Find(pvID));
    	}
    

    Now i can destroy the gameobject with masterclient and client but i still get these error:

    Failed to 'network-remove' GameObject. Client is neither owner nor masterClient taking over for owner who left: View (0)5002 on M4A1 PickUp(Clone)

    Ev Destroy for viewId: 5002 sent by owner: True this client is owner: False
  • Hi,

    You are sending DestroyOnNetwork to PhotonTargets.AllBuffered
    Try PhotonTargets.MasterClient instead.