RPC/PhotonView/NullReferenceException

Hallo. I am trying to change the Position of a GameObject (Tools) but get the NullReferenceException:Object reference not set to an instance of an object error in line " photonView.RPC("changep", RpcTarget.AllViaServer); ". The Script is attached on the GameObject Tools.
Thanks for any help.
    public class Tools : MonoBehaviour
    {
        public PhotonView photonView;
        
        private Vector3 vector3 = new Vector3(-22, 124, 0);

        void Awake()
        {
            photonView = PhotonView.Get(this);
        }
        #region PUN CALLBACKS
        [PunRPC]
        public void changep()
        {
            photonView.transform.position = vector3;
        }
        #endregion
        public void click()
        {
            photonView.RPC("changep", RpcTarget.AllViaServer);
        }
        
    }

Best Answer

Answers

  • Hi @Paladin83,

    please make sure, that you have a valid reference to the PhotonView component. Please also check, if the GameObject 'Tools' has an attached PhotonView component.
  • Hallo Christian_Simon. Thanks for the answer. There is a PhotonView component attached on the GameObject "Tools". How do i do a valid reference for the PhotonView component? I thought the reference is "photonView = PhotonView.Get(this);"
  • Paladin83
    Paladin83
    edited December 2018
    Thanks a lot. It works with "photonView = tools.GetComponent<PhotonView>();"
  • Paladin83
    Paladin83
    edited December 2018
    I mean "photonView = tools.GetComponent<PhotonView>(); "