Hi everyone, there was a tread about this problem but the thread did not help me. Here is a link to it. The ultimate solution was that the RPC was called by a child of the object that has the photon view compoment but in my case that is not the problem. I am trying to Instantiate a bomb that the player throws. The bomb variable is a prefab.
Here is my code:
private void FixedUpdate()
{
if (!photonView.IsMine && PhotonNetwork.IsConnected == true)
return;
if (shouldThrow)
{
shouldThrow = false;
gameObject.GetComponent<PhotonView>().RPC("createBomb", RpcTarget.AllViaServer);
}
}
[PunRPC]
public void createBomb()
{
GameObject c4 = Instantiate(
bomb,
new Vector3(camera.transform.position.x, camera.transform.position.y, camera.transform.position.z),
Quaternion.Euler(camera.transform.rotation.eulerAngles.x, camera.transform.rotation.eulerAngles.y + 90, camera.transform.rotation.eulerAngles.z)
);
c4.transform.position += camera.transform.forward;
c4.GetComponent<Rigidbody>().AddForce(camera.transform.forward * speed);
c4.GetComponent<Rigidbody>().AddForce(new Vector3(0, up, 0));
}
The error is in line 508 in the script PhotonNetworkPart:
for (int index = 0; index < argumentsTypes.Length; index++)
I debugged the code and turns out that the argumentsTypes
array is null. Can anybody help me?
EDIT:
here is the full stack trace:
NullReferenceException: Object reference not set to an instance of an object
Photon.Pun.PhotonNetwork.ExecuteRpc (ExitGames.Client.Photon.Hashtable rpcData, Photon.Realtime.Player sender) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:509)
Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2000)
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2785)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PeerBase.cs:640)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/EnetPeer.cs:552)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at C:/Dev/photon-sdk-dotnet/PhotonDotnet/PhotonPeer.cs:1548)
Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:205)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:139)
If you have any questions, let me know.