RPC function throws out NullReferenceException error

I'm trying to execute a simple void on all clients and I use RPC for that.
I want to execute this line of code: myPView.RPC("RPC_UpdateTaskBar", RpcTarget.All);

This should update an UI Slider for all players, but It throws out the error in the title.

The function itself looks like this:
[PunRPC]
public void RPC_UpdateTaskBar()
{
Debug.LogError("UpdateTaskBar got called");
taskBar.SetTaskBar(TasksDone);
}

I have a photon view attached to this component and I have also executed some other functions the same way in this script and it worked perfectly fine.

My question is, if there is anything wrong with this code, because maybe this does not work with a UI or something.

Notes (if that helps):
- this function gets called in another RPC function (this function was only targeted for the master client)
- myPView is the PhotonView that is attached to my game object

Thanks in advance
Max

Answers

  • if you call an RPC, you mustg have the receiving end of the rpc call in the SAME gameobject in the SAME class with the SAME photon view attached!!