PhotonView with ID x has no metod "x" marked with the [PunRPC](C#) property!

Options
Hello, I´m trying to make a multiplayer game and I want to destroy object but it says:
PhotonView with ID 3 has no method "LocalDestroy" marked with the [PunRPC](C#) or @PunRPC(JS) property!
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using Photon.Chat;

public class RayCast : MonoBehaviourPunCallbacks, IPunOwnershipCallbacks
{
    private static List<PhotonView> photonViewsToDestroy = new List<PhotonView>();

    public Transform camera;

    public LayerMask layerMask;

    public PhotonView view;

    void Update()
    {
        RaycastHit hit;
        if(Physics.Raycast(camera.position, camera.forward, out hit, 5f, layerMask) && Input.GetMouseButtonDown(0))
        {
            view = hit.transform.GetComponent<PhotonView>();
            DestroySceneObject(view);
        }
    }

    public static void DestroySceneObject(PhotonView photonView)
    {
        if (PhotonNetwork.IsConnected)
        {
                if (photonView.IsMine)
                {
                    PhotonNetwork.Destroy(photonView);
                }
                else
                {
                    photonView.RequestOwnership();
                    photonViewsToDestroy.Add(photonView);
                }
                photonView.RPC("LocalDestroy", RpcTarget.AllBuffered, photonView.ViewID);
        }
        else
        {
            GameObject.Destroy(photonView.gameObject);
        }
    }

    public void OnOwnershipRequest(PhotonView targetView, Player requestingPlayer)
    {
    }

    public void OnOwnershipTransfered(PhotonView targetView, Player previousOwner)
    {
        if (photonViewsToDestroy.Remove(photonView))
        {
            PhotonNetwork.Destroy(photonView);
        }
    }

    [PunRPC]
    private void LocalDestroy(int viewId)
    {
        GameObject.Destroy(PhotonView.Find(viewId).gameObject);
    }
}

Comments

  • TheJacob
    Options
    ehm
  • TheJacob
    Options
    nobody ?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited March 2020
    Options
    Hi @TheJacob,

    Thank you for choosing Photon!

    why do you need to manually destroy networked scene object locally?
    PhotonNetwork.Destroy already does that for you!

    In case you must use the manual destroy, to debug this:

    - make sure RPC method LocalDestroy is on the list from PhotonServerSettings
    - make sure to call the RPC on the right PhotonView: RayCast component should be attached to the same GameObject as the one w/ PhotonView (here w/ ViewID = 3)...you could log the ViewID of the PhotonView from RayCast...
    view = hit.transform.GetComponent<PhotonView>();
    
    here hit GameObject needs to have RayCast or any component that has LocalDestroy RPC method. is it the case?