RPC/PhotonView/NullReferenceException
Options
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 "
Thanks for any help.
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); } }
0
Best Answer
-
Please try using
photonView = GetComponent<PhotonView>();
instead.5
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.1 -
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);"0
-
Please try using
photonView = GetComponent<PhotonView>();
instead.5 -
Thanks a lot. It works with "
photonView = tools.GetComponent<PhotonView>();
"0 -
I mean "
photonView = tools.GetComponent<PhotonView>();
"0