Search Unity

Third Party Photon RPC calling

Discussion in 'Multiplayer' started by j_perker, Feb 22, 2014.

  1. j_perker

    j_perker

    Joined:
    Feb 20, 2014
    Posts:
    19
    Code (csharp):
    1. void OnTriggerEnter(Collider myTrigger){
    2.        if (myTrigger.gameObject.tag == "bullet"  photonView.isMine){
    3.          playerHealth -= 1;
    4.          Debug.Log ("player health:" + playerHealth);
    5.          photonView.RPC ("DestroyBullet", PhotonTargets.All, myTrigger.gameObject);
    6.          if (playerHealth <= 0){          
    7.           PhotonNetwork.Destroy(this.gameObject);
    8.          }
    9.  
    10.        }
    11.     }
    12.  
    Code (csharp):
    1. [RPC]
    2. void DestroyBullet(GameObject go)
    3. {
    4.     PhotonNetwork.Destroy(go.gameObject);
    5. }
    So i'm trying to have it when the bullet hits your player on your client, the bullet gets destroyed everywhere. To do this i'm sending out an RPC when the bullet collides with the player and I want to pass in the collider to the rpc function but anything I try doesn't work and the bullet doesn't get deleted. Any ideas?

    Any help?
     
  2. emre2345DH

    emre2345DH

    Joined:
    Apr 17, 2013
    Posts:
    28
    You should call PhotonNetwork.Destroy only once in OnTriggerEnter function. Because it destroys the object over the network on all clients. Except this the object must be instantiated using PhotonNetwork.Instantiate and must have networkView component on it.
     
  3. j_perker

    j_perker

    Joined:
    Feb 20, 2014
    Posts:
    19
    I tried that but then I get this error-
    failed to 'network-remove' GameObject. Client is neither owner nor masterClient taking over for owner who left: View (0)2005
     
  4. jim_dodge

    jim_dodge

    Joined:
    Jan 24, 2014
    Posts:
    3
    are you inheriting from Photon.MonoBehaviour in all related classes AND have PhotonViews instead of NetworkViews? I ran into similar error messages before figuring that out. Another thing to check is that the PhotonView is set up in the inspector correctly, with the transform of the object put in the "Observe:" section of this component. It is easy to forget that with prefabs that are not instantiated until runtime.
     
  5. j_perker

    j_perker

    Joined:
    Feb 20, 2014
    Posts:
    19
    Yes I'm inheriting from Photon.MonoBehavior, yes there are PhotonViews, and I had it observing the rigidbody, but I changed it to the transform and I got the same error. Didn't work.
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    The problem is that you can't send a GameObject as parameter. It should log an error to your console on the calling client.

    In the network, all GameObjects are identified by a PhotonView (equivalent to Unity's NetworkView). One client's GameObject might have another ID on another.
    You could send the PhotonView's view ID but you don't have to: You call the RPC on a specific "networked" GameObject. The others in the room will automatically pick that GO and call the fitting method on that instance (only).
    You also don't have to inherit from PhotonMonoBehaviour. It's just adding the property photonView. And: You also don't have to observe a script to get RPC calls on it. It just has to be on the GameObject with the PhotonView that was used for the call on the remote machine.

    Don't instantiate bullets. They are too short-lived and Instantiate/Destroy adds quite some overhead where you can simply move the bullet, let it collide and get rid of it.

    Hope that helps.
     
  7. danish115

    danish115

    Joined:
    Aug 28, 2014
    Posts:
    47
    i want to play the game play scene when there may be more than one and less than 5 players are in the room. anybody can tell me how it is possible? I also want to check the time. After that time is over more than one and less than 5 players automatically play the game play scene. i have searched all the way but there is no clue, hint or anything else related to my problem. I think photon only supports the players enter game play scene one by one. I have never found any demo , example according to this problem like more than one player enter in the room and play the game play scene simultaneously. if there is any demo, example, tutorial or anything else please refer me and i am thinking that photon do not support this type of things. if support it the give me any reference tutorial. if not then also do let me confirm by you. It will be very thankful to you.
     
  8. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
  9. Pulov

    Pulov

    Joined:
    Feb 20, 2010
    Posts:
    824
    Hi. I've an issue with passing parameters, is this the way I'm supossed to send them?
    When method is called in teh offline mode it does work ok.

    switch_LR is an int and the other is a vector 3

    Code (CSharp):
    1.         //si estamos jugando en ofline o para mis efectos.
    2.                 if( oflineMode == true )
    3.                 {
    4.                 Debug.Log("disparo offlineMode");
    5.                 BroadcastMessage ( "Fire_Linkage" , Switch_LR , SendMessageOptions.DontRequireReceiver ) ;
    6.                 }
    7.  
    8.                 if( oflineMode == false)
    9.                 {
    10.                 //si estamos jugando online llamamos al disparo como un RPC para que se sincronice en otros jugadores.
    11.                     pV.RPC ("Fire_Linkage", PhotonTargets.All, Switch_LR);
    12.                 Debug.Log("firing RPC");
    13.                 }
    14.  
    15.             }
    16.  
    17.             //RETROCESO
    18.             if( oflineMode == true ){
    19.             BroadcastMessage ( "Generate_Recoil" , transform.forward , SendMessageOptions.DontRequireReceiver ) ;
    20.             Reload_Flag = false ;
    21.             StartCoroutine ( "Reload" ) ;
    22.             }
    23.            
    24.             if( oflineMode == false){
    25.                 pV2.RPC ("Generate_Recoil",PhotonTargets.All,transform.forward );
    26.                 Reload_Flag = false ;
    27.                 StartCoroutine ( "Reload" ) ;
    28.             }
     
  10. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    @Pulov: In general, it should be fine this way. Anything in the log? The methods are in a script on a GameObject with PhotonView?
     
  11. danish115

    danish115

    Joined:
    Aug 28, 2014
    Posts:
    47
    I have a problem with gui textures when we join the room and play the game ... the pause button, acceleration paddle and other gui textures are shown of both players. Basically the textures are overlapping each other.
    any solution ??
     
  12. Pulov

    Pulov

    Joined:
    Feb 20, 2010
    Posts:
    824
    Pff I would say yes but I'm going to go trough the code again, slowly and see if I find the thing. Its crazy because in offline mode it works so I told myself, sure its the param sent must be sent in other way, but as I did not see any errors in console... I'll tell how it goes.

    danish115. Check the title of this thread.
     
  13. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    How about searching for a suitable thread? Or creating one?
    This is off topic but your solution will be to show only one GUI. The one that should be active for "your" game object. Check isMine and disable GUIs on GOs that are not yours.
     
  14. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    In offline mode you don't use RPCs, so it might work for some other reason. Check if you put the [RPC] attribute on top of the method you want to be able to call as RPC. When you have to change this, make sure to test with clients of the same build, or else the RPC list (in PhotonServerSettings) won't be identical on all clients and it will fail due to that.
     
  15. Pulov

    Pulov

    Joined:
    Feb 20, 2010
    Posts:
    824
    Ok, my fault.
    I should have debug.log to see the params where correctly being send. I'll blame the heat location that appeared in my city for not doing thiso_O

    I was using broadcast message for a reason.. There are a couple of methods with same name for the recoil to occur in separated scripts.
    ....
    Now I've the recoil working.

    I've to check the bullet type now, I guess it is gonna be a very similar fault from my part.

    At the moment, it spawns the projectile in all clients but of different type in each. but probalby is not going to be Photon related.