PunRPC cannot be called on scene objects by themselves?

Options

Hi, I have guns in my game that have booleans defining if they are grabbed or not. To sync their state to other clients I decide to use an RPC method:

 [PunRPC] private void SetGrabbedState(bool grabbed) => isGrabbed = grabbed;

When the player grabs them, the RPC is called, but I get an error talking about my method being static, which is not as you can see.

After a little research I've heard about other users having similar problems, apparently is related to the photonViewID. Note that my guns are scene objects placed before the scene runs (not at runtime)

Any idea of how to work around it?

Best Answer

  • Tobias
    Tobias admin
    Answer ✓
    Options

    Apparently PUN is not finding the method. Maybe it is related to the abstract class defining it. How about you try to add the method (or one with a similar name to test this) in the derived class and give it a go?

    I would not call RPCs in a property setter. This a) gets forgotten easily and will overload the network and b) it seems to be a case for Custom Properties instead.

Answers

  • Tobias
    Options

    Without exact error log, we can only guess.

  • ChichoRD
    Options

    I did not wanted to put a copy-paste of the error log to explain my problem, but I guess it's really needed:

    RPC method 'SetGrabbedState(Boolean)' not found on object with PhotonView 1. Implement as non-static. Apply [PunRPC]. Components on children are not found. Return type must be void or IEnumerator (if you enable RunRpcCoroutines). RPCs are a one-way message.
    UnityEngine.Debug:LogErrorFormat (UnityEngine.Object,string,object[])
    Photon.Pun.PhotonNetwork:ExecuteRpc (ExitGames.Client.Photon.Hashtable,Photon.Realtime.Player) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:638)
    Photon.Pun.PhotonNetwork:RPC (Photon.Pun.PhotonView,string,Photon.Pun.RpcTarget,Photon.Realtime.Player,bool,object[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1264)
    Photon.Pun.PhotonNetwork:RPC (Photon.Pun.PhotonView,string,Photon.Pun.RpcTarget,bool,object[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:2924)
    Photon.Pun.PhotonView:RPC (string,Photon.Pun.RpcTarget,object[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:604)
    GrabbableObject:set_IsGrabbed (bool) (at Assets/Scripts/Objects/Grabbables/GrabbableObject.cs:13)
    GrabbableObject:Grab (UnityEngine.Transform) (at Assets/Scripts/Objects/Grabbables/GrabbableObject.cs:36)
    PlayerManager:Interact (UnityEngine.InputSystem.InputAction/CallbackContext) (at Assets/Scripts/Player/PlayerManager.cs:90)
    UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
    UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)
    
    
    

    Additional data that may contribute to the problem:

    • The method is implemented in an abstract class (Althought the script attached to the gameObject is not abstract itself, but a derived class)
    • The method is called inside the setter of a property of the class
    • The method is declared using the lambda operator

    I attached the script with the class itself and when the property it's set:


  • Tobias
    Tobias admin
    Answer ✓
    Options

    Apparently PUN is not finding the method. Maybe it is related to the abstract class defining it. How about you try to add the method (or one with a similar name to test this) in the derived class and give it a go?

    I would not call RPCs in a property setter. This a) gets forgotten easily and will overload the network and b) it seems to be a case for Custom Properties instead.

  • ChichoRD
    Options

    Would have liked to get around with the RPC but finally opted for Room Custom Properties as you said