Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Photon RPC Error

Discussion in 'Multiplayer' started by Mucahit53, Jan 10, 2022.

  1. Mucahit53

    Mucahit53

    Joined:
    Dec 15, 2020
    Posts:
    10
    Hey

    i've got a problem about photon

    when i try to equip my weapon, unity throws error

    upload_2022-1-10_18-55-46.png
    Code (CSharp):
    1.         if (Input.GetKeyDown(pickUpKey) && weaponInRadius != null)
    2.         {
    3.             photonView.RPC("PickUpGun", RpcTarget.AllBufferedViaServer);
    4.         }
    5.  
    6.  
    7. [PunRPC]
    8.     void PickUpGun()
    9.     {
    10.        
    11.         weaponInRadius.transform.SetParent(weaponHolder.transform);
    12.         wac2.EquipGun();
    13.         weaponInRadius.GetComponent<Rigidbody>().isKinematic = true;
    14.         weaponInRadius.GetComponent<Collider>().enabled = false;
    15.         weaponInRadius.transform.localPosition = Vector3.zero;
    16.         weaponInRadius.transform.localRotation = Quaternion.identity;
    17.  
    18.         currentHeldWeapon = weaponInRadius.GetComponent<Weapon>();
    19.  
    20.         if (weaponInRadius.gameObject.name == "Weapon_Katana")
    21.         {
    22.             currentHeldWeapon.weaponStats.weaponType = WeaponType.KATANA;
    23.         }
    24.         else if (weaponInRadius.gameObject.name == "Weapon_LightSaber")
    25.         {
    26.             currentHeldWeapon.weaponStats.weaponType = WeaponType.LIGHTSABER;
    27.         }
    28.  
    29.        
    30.     }
    31.  
    32.  
    33.  
     
  2. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    How is your prefab setup here? Is this component on your player? Is there a localplayer/ismine check not shown before processing the pickUpKey input?
     
  3. Mucahit53

    Mucahit53

    Joined:
    Dec 15, 2020
    Posts:
    10
    upload_2022-1-10_21-11-1.png

    The script i wrote above is in WeaponManager object

    yes there is isMine check

    upload_2022-1-10_21-12-44.png
     
  4. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    207
    The issue is that the script with the RPC is on WeaponManager, but the cached photonView I assume is on the root object? You can't do it quite like that. You could use an event instead, or have the RPC on the parent object and have the child object call that instead.
     
  5. Mucahit53

    Mucahit53

    Joined:
    Dec 15, 2020
    Posts:
    10
    Thanks a lot it really helped
     
    toddkc likes this.