Photon RPC only half of it works? Any ideas?

Okay here’s my dilemma. My shotgun is shooting PERFECTLY. However, the bullet holes (Only create on MY client). The other player just don’t see them.

(This is for Photon).

yes I have the RPC to Target all players. It just won’t work unless I do PhotonNetwork.Instantiate (which I know that’s not good to do so I won’t).

But here is my entire RPC Function. Can you please help me?

     [PunRPC]
         void ShotgunShoot(){
             // This is the shooting for The Beast Double Barrel ShotGun
             Ray ray;
             RaycastHit hit;
             Vector3 tempVec;
             for(int i = 0; i < 30; i++){
                 tempVec = Vector3.Slerp(MyCamera.transform.forward, Random.onUnitSphere, 0.05f);
                 ray = new Ray(MyCamera.transform.position, tempVec);
                 if(Physics.Raycast(ray, out hit,100f)){
                     if(hit.collider.tag == "Map"){
                         GameObject BulletHole;
                         // TRIED BOTH THE RESOURCES LOAD AND REGULAR INSTANTIATE
    
                         BulletHole = Instantiate(Resources.Load("StoneDecal"),hit.point,Quaternion.FromToRotation(Vector3.up, hit.normal))as GameObject;
                         Instantiate(Decal,hit.point,Quaternion.FromToRotation(Vector3.up, hit.normal));
                     }
                     if(hit.collider.tag == "Player"){
                         // THIS DAMAGES THE PLAYER. (THIS WORKS PROPERLY). It's just the above (only works on MY client, not both)
                         playerHealth = hit.transform.gameObject.GetComponent<_PlayerHealth>();
                         playerHealth.gameObject.GetComponent<PhotonView>().RPC ("TakeDamage", PhotonTargets.Others, DamageAmt);
                     }
                 }
             }
         }

Anyone? I am seriously confused beyond belief to why this isn’t working.
Why will it deal damage to the player, but not instantiate bulletholes?

I even put inside if(hit.collider.tag == “Map”) another RPC as well to try to instantiate bulletholes,
and the same exact scenario - deals damage to player, creates bulletholes locally on the person who shot the gun, but nobody else.

Is there something I am just plainly doing wrong here?

Here’s the new code -

[PunRPC]
    void ShotgunShoot(){
        // This is the shooting for The Beast Double Barrel ShotGun

        // The rays, hits, and tempVector are at top now (so I can call hit from BulletHoleContact.
        //    Ray ray;
        //    RaycastHit hit;
        //    Vector3 tempVec;
            for (int i = 0; i < 30; i++) {
                tempVec = Vector3.Slerp (MyCamera.transform.forward, Random.onUnitSphere, 0.05f);
                ray = new Ray (MyCamera.transform.position, tempVec);
                if (Physics.Raycast (ray, out hit, 100f)) {
                    if (hit.collider.tag == "Player") {
                        // THIS DAMAGES THE PLAYER. (THIS WORKS PROPERLY). It's just the above (only works on MY client, not both)
                        playerHealth = hit.transform.gameObject.GetComponent<_PlayerHealth> ();
                        playerHealth.gameObject.GetComponent<PhotonView> ().RPC ("TakeDamage", PhotonTargets.Others, DamageAmt);
                    }
                    if (hit.collider.tag == "Map") {
                        photonView.RPC ("BulletHoleContact", PhotonTargets.All, null);

                        //GameObject BulletHole;
                        // TRIED BOTH THE RESOURCES LOAD AND REGULAR INSTANTIATE
                   
                        //    BulletHole = Instantiate(Resources.Load("StoneDecal"),hit.point,Quaternion.FromToRotation(Vector3.up, hit.normal))as GameObject;
                        //BulletHole = Instantiate(Decal,hit.point,Quaternion.FromToRotation(Vector3.up, hit.normal))as GameObject;
                    }
                }
            }
            //CanShoot = false;
        }

    #endregion
    [PunRPC]
    void BulletHoleContact(){
        GameObject BulletHole;
        BulletHole = Instantiate(Resources.Load("StoneDecal"),hit.point,Quaternion.FromToRotation(Vector3.up, hit.normal))as GameObject;
        //Instantiate(Decal,hit.point,Quaternion.FromToRotation(Vector3.up, hit.normal));
    }

A RPC is always called on some PhotonView. PhotonViews are either setup the Editor and loaded with the scene or created at runtime with PhotonNetwork.Instantiate.
The RPC will be executed on the GameObject that has the PhotonView you used in photonView.RPC() but you can of course affect anything else in the scene.

I’m tempted to simply say yes. :wink:
You use an RPC to everyone, which will cause another 30 RPCs to All/Others on every single client in the room.

Better: Don’t trigger more RPCs in ShotgunShoot. Where the wall-hits are, does not matter so much, they can be random on each client and don’t have to be positioned correctly.
What matters are the hits of players. Only the shooting player should send those. In the for loop, detect hits if photonView.isMine. Only increase a damageSum. When the loop is done, you have the accumulated damage. Send that.

Any receiver will execute the ShotgunShot on your character. I hope “MyCamera” relates to the charater’s view.

Hey Tobias. Thanks for the reply.
I handled it - I downgraded Unity and went to an older Photon and now it works. (There must be a bug somewhere in the new version). Everything works perfectly now sense I downgraded and changed to older version of Photon.

EDIT - And the Camera. I’m using it so my bullet holes show in proper place, otherwise they only shoot straight and no other direction lol.

I do have an off-topic question though, is there a way to check the MSG/S on the Photon Server? I’ve tried to check the logs, but don’t see that anywhere. (I’d just like to personally know what my MSG/S are.

You should still refactor your RPC, because logic-wise, it will create a chain reaction of RPCs, which will flood your game.

You run your own Photon Server? It has “PerfMon Counters” for almost anything you could be interested in. In PhotonControl, under “PerfMon Counters”, click “Install Counters”. Run Photon and your clients. In the submenu in PhotonControl, you can also “Open Perfmon”.

Please update your question in answers :slight_smile:
http://answers.unity3d.com/questions/1003399/rpc-acting-strangly.html

Thanks again buddy.

Then that leads to me to the question, how would I got about roughly getting the proper direction? Or you you think its wise to create only local bullet holes(just for the one shooting)? Which I don’t mind doing, as it’s a DN3D Style game.
So no big deal.

Awesome! Thanks.

And will do haha

I totally would do the holes locally. Don’t forget: Your players won’t sit there side by side and compare where the holes are. They care about the general look of things and that health is reduced correctly.

Yeah that is really true. That’s what I’ll do then. But what about things like grenades exploding, do you think it’s already to make a huge bomb mark? I mean after all explosives are far less than rapid fire machine guns hahaah.

Grenades have some time before they explode. This should give you some time to sync where and when it happens.
Again, I would not sync where exactly pieces of debris go and where you have explosion-marks on walls, etc…