PunRPC NOT WORKING!!!

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

PunRPC NOT WORKING!!!

petersenjmp
2020-03-16 10:01:28

Hi,

I have a bunch of particle systems and Photon is not showing them to anybody else.
Here I try to RPC engine smoke and sparks and it's not working:

public PhotonView pv;


void Update () {  
    if (pv.isMine) {

        Smoke();

    }  
    GetComponent<PhotonView>().RPC("Smoke", PhotonTargets.All);

}  
[PunRPC]  
void Smoke()  
{

    if (h.BlackSmokeStage1)  
    {  
        ParticleSystem.EmissionModule nem = sparks.emission;  
        nem.rateOverTime = 10f;  
        ParticleSystem.EmissionModule nem2 = BSmoke.emission;  
        nem2.rateOverTime = 10f;  
    }   

}

Why doesn't this work?

Another question is, why is one of the particle systems I mentioned showing to all even though I don't RPC it, and all others don't show regardless?

Comments

Tobias
2020-03-16 16:06:55

If you don't RPC the particle system but it shows, then maybe some script enabled it.

If you call the RPC, does the local player show the smoke?
Does every remote player know the networked object? Is there anything in the logs?

At the moment, I can't know what's up, as I only see the classes, not the objects.
Please add Debug.Log() anywhere useful and log your way through the execution.

I can also point to the docs on RPCs. Maybe those help:
https://doc.photonengine.com/en-us/pun/current/gameplay/rpcsandraiseevent

petersenjmp
2020-03-17 06:54:56

Okay I have this error: NullReferenceException: "Object reference not set to an instance of an object
BlackSmoke.Update () (at Assets/BlackSmoke.cs:33)" it references the line : "GetComponent().RPC("Smoke", PhotonTargets.All);"

The smoke is shown on the player but not to anyone else, so I know that the particle system is working and active.

I'm not sure what you mean by : Does every remote player know the networked object? They all have photon views and can see each other if thats what you mean. Also when I normally RPC like in the code I posted it works perfectly with 3D objects.

Why is it saying theres no reference to "Smoke", when the function "Smoke()" is PunRPC's and right beneath the line "GetComponent().RPC("Smoke", PhotonTargets.All);"??

Tobias
2020-03-17 07:56:07

Well, that may be some setup issue or such. Do you do something with a local character that you don't do for remote ones?
This is not really a networking problem. The nullreference doesn't happen because the RPC is not working but because it does and some reference is missing.

Find out which value is null and look up where you normally set it up.

petersenjmp
2020-03-19 09:14:20

Hi Tobias,

All players have the exact same setup but I fixed the error by assigning the Photon view in the inspector. however it only sent the RPC it was never received so I decided to do the RPC from a different script on thee same gameobject. I believe I'm getting closer because now I'm sending and receiving the RPC for the smoke, but the smoke is still only visible to the player locally for some reason.

this is the smoke script that I dont' RPC anything from anymore (I RPC the enablement of the game object which parents the particle systems in another script -> see below):
public class BlackSmoke : Photon.MonoBehaviour {

public Health h;  
public ParticleSystem sparks;  
public ParticleSystem BSmoke;  
ParticleSystem.EmissionModule emissionModule1;  
ParticleSystem.EmissionModule emissionModule2;

public PhotonView pv;

bool one = true;  
//bool two = false;

// Use this for initialization  
void Start () {  
    h.GetComponent<Health>();  
    emissionModule1 = sparks.emission;  
    emissionModule2 = BSmoke.emission;


}

// Update is called once per frame  
void Update () {  
    if (pv.isMine /*&& one*/)  
    {

        smokes();


        //pv.RPC("smokes", PhotonTargets.All);  
        //one = false;  
    }

}  
[PunRPC]  
void smokes()  
{

    if (h.BlackSmokeStage1)  
    {  
        ParticleSystem.EmissionModule nem = sparks.emission;  
        nem.rateOverTime = 10f;  
        ParticleSystem.EmissionModule nem2 = BSmoke.emission;  
        nem2.rateOverTime = 10f;  
    }  
    if (h.BlackSmokeStage2)  
    {  
        ParticleSystem.EmissionModule nem = sparks.emission;  
        nem.rateOverTime = 25f;  
        ParticleSystem.EmissionModule nem2 = BSmoke.emission;  
        nem2.rateOverTime = 50f;  
    }  
    if (h.BlackSmokeStage3)  
    {  
        ParticleSystem.EmissionModule nem = sparks.emission;  
        nem.rateOverTime = 50f;  
        ParticleSystem.EmissionModule nem2 = BSmoke.emission;  
        nem2.rateOverTime = 100f;  
    }  
}  

}

This is what I do to enable the game object and the script above:
public GameObject blackSmoke;
public PhotonView pv;

[PunRPC]  
void ShowSmoke()  
{


    blackSmoke.SetActive(true);


}  

void Start ()
{

    if(pv.isMine)  
    {  
        photonView.RPC("ShowParti", PhotonTargets.All);  
        photonView.RPC("ShowSmoke", PhotonTargets.All);  
    }

}

This is the messages in the console:
Sending RPC "ShowSmoke" to target: All or player:.
UnityEngine.Debug:Log(Object)
NetworkingPeer:RPC(PhotonView, String, PhotonTargets, PhotonPlayer, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3804)
PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2936)
PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:597)
ActivateGuns:Start() (at Assets/ActivateGuns.cs:145)

and

Received RPC: ShowSmoke
UnityEngine.Debug:Log(Object)
NetworkingPeer:ExecuteRpc(Hashtable, Int32) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2946)
NetworkingPeer:RPC(PhotonView, String, PhotonTargets, PhotonPlayer, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3858)
PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2936)
PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:597)
ActivateGuns:Start() (at Assets/ActivateGuns.cs:145)

So it should be working now. I'm RPC'ing the function that enables the gameobject that has the smoke emitters as children, and the smoke is visible locally, but no one else can see it...... It makes ZERO sense to me at this point... If you can help me I would really appreciate it

petersenjmp
2020-03-19 10:25:19

So I found out that instantiating a prefab works with particles and NOT RPC!!! That info should be broadcast to all developers because it makes no sense but that's the ONLY way in which particles can be seen on everyones computers and not just locally.

Tobias
2020-03-23 10:35:29

Received RPC: ShowSmoke

It would be interesting to know if the other clients also have this in the log. Then it means that at least the RPC itself arrives. Then the networking part of this works...

Phenomena
2020-03-24 12:52:03

RPC function needs to be public, that's your issue

Back to top