Search Unity

Nullref and RPC method error

Discussion in 'Multiplayer' started by GroundstompStudios, Jun 7, 2021.

  1. GroundstompStudios

    GroundstompStudios

    Joined:
    Dec 25, 2016
    Posts:
    50
    Hey everyone. I'm currently developing a FPS game, and I'm trying to make it where the player can deal damage to other players. Right now, I'm getting an error that make's this impossible for that to work.

    The two errors I am getting:

    NullReferenceException: Object reference not set to an instance of an object (WeaponController.cs:77

    Code (CSharp):
    1. if (!PhotonView.IsMine) // error here
    2. {
    3.      return;
    4. }
    Then I am also getting an error of: RPC method 'RPC_TestFire()' not found on object with PhotonView 1002. Implement as non-static. Apply [PunRPC]. Components on children are not found. Return type must be void or IEnumerator. RPCs are a one-way message.

    That is on this line:
    Code (CSharp):
    1. PhotonView.RPC("RPC_TestFire", RpcTarget.All);
    And the function for that is this:
    Code (CSharp):
    1. [PunRPC]
    2.         public void RPC_TestFire()
    3.         {
    4.             Debug.Log("Shooting");
    5.             RaycastHit hit;
    6.            
    7.             if (Physics.Raycast(fpCamera.transform.position, fpCamera.transform.forward, out hit, equipment.bulletRange))
    8.             {
    9.                 Debug.Log("Hit");
    10.             }
    11.         }
    If someone can help me figure this out. That'd mean a lot.

    I also have these on the player, saying that the player is mine, but that the gun isn't.

    Player:
    upload_2021-6-7_14-17-21.png

    AKM which is child of player:
    upload_2021-6-7_14-18-3.png
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    For some reason, the PhotonView is null for your script. This is likely related to the setup of the object.

    The gun's PhotonView does not have a ViewID (it's 0), so this may be a problem. Instantiate it via PhotonNetwork.Instantiate.