Specific RPC not firing but all others are working

Options
Hello there,

I've set up a scene where a bunch of things happen in the pre-game setup. Then one player hits the start game button, and it should be sending an RPC call to all players but the RPC is only running on the game that hits the button.

All of the other RPC calls are working properly, and this RPC used to work just fine. I haven't changed anything in it and I'm not really sure what is going on with it. If anyone has any insight I would love the assistance.

Here is some of the relevant code:
[code2=csharp]public void StartSimulationClicked(){
StartupPhotonView.RPC("SendOrder",PhotonTargets.All, orderOfDeployment, startFireTrackBool, scenarioNumber); //calls the SendOrder RPC to send the order to all players,
//as well as other information
}[/code2]


[code2=csharp][RPC]
public void SendOrder(string[] orderedArr, bool[] startingFires, int scenNum){
Debug.Log ("Send order running");
orderOfDeployment = orderedArr; //set the order of deployment for all users
startFireTrackBool = startingFires; //set the boolean array to equal the proper starting fires
scenarioNumber = scenNum; //sets the local var for the player for which scenario number it is
FireSimLogic.scenarioNum = scenarioNumber; //set the scenario number that is passed to the next the scene
FireSimLogic.startingFireList = startFireTrackBool; //set which starting fires are present for the next scene for all users
FireSimLogic.dispatchOrder = orderOfDeployment; //set the dispatch order for all users to display in the CAD
Application.LoadLevel(1); //Load the CAD Scene
}[/code2]

The debug log never happens on the other windows. The StartSimulationClicked function runs on the single player, but sends the RPC out, so it should be going to all players I believe.

Am I missing something that you all notice?

Comments

  • Tobias
    Options
    I assume orderOfDeployment is a string[], the second a bool[]?
    I never tried this scenario (mixing a array parameter with other parameters). Maybe this parameter combination is causing the problem.

    You could turn the parameters into a object[]. In it, the first item would be a string[], then a bool[] and the int.
    Pass this single parameter to RPC and expect this single parameter in the method to be called.
  • iHaveReturnd
    Options
    You are correct in your assumptions. they are a string[] and bool[] respectively.

    So I would need to type cast the string[] and bool[] to be object[]? then put them in the object array?

    Would this mess up the data when retrieving it or can they type cast back into bool/strings without issue?

    So just:
    [code2=csharp]objectArray[0] = stringArray as object[][/code2]

    And after it's been received:

    [code2=csharp]holderVar = objectArray[0] as string[][/code2]

    Is this what you mean?
    Thank you for your help, I really appreciate it.
  • Tobias
    Options
    I meant (written out of my head without ide confirming my code):

    object[] rpcParameters = new object[3];
    rpcParameters[0] = theStringArray;
    rpcParameters[1] = theBoolArray;
    rpcParameters[3] = theInt;
  • iHaveReturnd
    Options
    I suppose I should have specified in my post. I tried that before my last post, and it isn't happy with the types. Gives an error with type mismatch for object and string, and object and bool.

    Thus why I asked about the type casting question.

    Here's how I have it now just to clarify:

    [code2=csharp]public void StartSimulationClicked(){
    object[] arraysToSend = new object[2];
    arraysToSend[0] = orderOfDeployment;
    arraysToSend[1] = startFireTrackBool;
    StartupPhotonView.RPC("SendOrder",PhotonTargets.All, arraysToSend, scenarioNumber); //calls the SendOrder RPC to send the order to all players,
    //as well as other information[/code2]

    and:

    [code2=csharp][RPC]
    public void SendOrder(object[] receivedArrays, int scenNum){
    Debug.Log ("Send order running");
    orderOfDeployment = receivedArrays[0]; //set the order of deployment for all users
    startFireTrackBool = receivedArrays[1]; //set the boolean array to equal the proper starting fires
    scenarioNumber = scenNum; //sets the local var for the player for which scenario number it is
    FireSimLogic.scenarioNum = scenarioNumber; //set the scenario number that is passed to the next the scene
    FireSimLogic.startingFireList = startFireTrackBool; //set which starting fires are present for the next scene for all users
    FireSimLogic.dispatchOrder = orderOfDeployment; //set the dispatch order for all users to display in the CAD
    Application.LoadLevel(1); //Load the CAD Scene

    }[/code2]

    And it gives the cannot implicity conver type 'object' to 'string[]', and same for bool.

    Any thoughts on that?
  • iHaveReturnd
    Options
    EDIT: I just fond a work around/solution. I'll add it to the bottom of this post.

    So as an update, I tried separating all of the pieces of the RPC to try and isolate the issue.

    So now I have:

    [code2=csharp]public void StartSimulationClicked(){

    StartupPhotonView.RPC ("SendUnitDispatchOrder",PhotonTargets.All,orderOfDeployment); //string[]
    StartupPhotonView.RPC ("SendScenarioNumber",PhotonTargets.All, scenarioNumber); //int
    StartupPhotonView.RPC ("SendStartingFires",PhotonTargets.All, startFireTrackBool); //bool[]
    StartupPhotonView.RPC ("GoToCAD",PhotonTargets.All); //Load Level function
    }[/code2]


    *The problem RPC that doesn't run* The debug is never output to the receiving (or lack there of) players
    [code2=csharp][RPC]
    public void SendUnitDispatchOrder(string[] receivedString){
    Debug.Log ("Sendunit running");
    orderOfDeployment = receivedString;
    FireSimLogic.dispatchOrder = orderOfDeployment; //set the dispatch order for all users to display in the CAD
    }[/code2]

    This RPC Works
    [code2=csharp][RPC]
    public void SendScenarioNumber(int scenNum){
    Debug.Log ("Sending scenario Number");
    scenarioNumber = scenNum; //sets the local var for the player for which scenario number it is
    FireSimLogic.scenarioNum = scenarioNumber; //set the scenario number that is passed to the next the scene
    }[/code2]

    This RPC Works
    [code2=csharp][RPC]
    public void SendStartingFires(bool[] receivedBool){
    Debug.Log ("SendStartingFires Running");
    startFireTrackBool = receivedBool; //set the boolean array to equal the proper starting fires
    FireSimLogic.startingFireList = startFireTrackBool; //set which starting fires are present for the next scene for all users
    }[/code2]

    This RPC Works
    [code2=csharp][RPC]
    public void GoToCAD(){
    Debug.Log ("Loading Level");
    Application.LoadLevel(1); //Load the CAD Scene
    }[/code2]

    The ONLY RPC that is not working is the SendUnitDispatchOrder, which is the cut down version of "SendOrder" from before. That is a very key part of the function to be sent. There are no errors when it should get sent, both from the one clicking the button and the receivers of the RPC, it just doesn't seem to run... I tried rewriting it just for kicks to no avail.



    EDIT: So it appears that there is an issue with sending string arrays as parameters? What I ended up doing as a fix was breaking down the array, and sending each index as an individual string, then reconstructed the array in the RPC. It's sort of a janky hack, but it works. Here's what I mean in the code in case that was unclear:


    [code2=csharp]public void StartSimulationClicked(){
    Debug.Log (orderOfDeployment[0]);

    StartupPhotonView.RPC ("SendUnitDispatchOrder",PhotonTargets.All, orderOfDeployment[0],orderOfDeployment[1],orderOfDeployment[2],orderOfDeployment[3],orderOfDeployment[4],orderOfDeployment[5],orderOfDeployment[6],orderOfDeployment[7]);
    StartupPhotonView.RPC ("SendScenarioNumber",PhotonTargets.All, scenarioNumber);

    StartupPhotonView.RPC ("SendStartingFires",PhotonTargets.All, startFireTrackBool);
    StartupPhotonView.RPC ("GoToCAD", PhotonTargets.All);
    }

    [RPC]
    public void SendUnitDispatchOrder(string receivedString0, string receivedString1, string receivedString2, string receivedString3, string receivedString4, string receivedString5, string receivedString6, string receivedString7){
    Debug.Log ("Sendunit running");
    orderOfDeployment[0] = receivedString0;
    orderOfDeployment[1] = receivedString1;
    orderOfDeployment[2] = receivedString2;
    orderOfDeployment[3] = receivedString3;
    orderOfDeployment[4] = receivedString4;
    orderOfDeployment[5] = receivedString5;
    orderOfDeployment[6] = receivedString6;
    orderOfDeployment[7] = receivedString7;
    FireSimLogic.dispatchOrder = orderOfDeployment; //set the dispatch order for all users to display in the CAD
    }[/code2]
  • Tobias
    Options
    Thanks for all the analysis. It seems I will have to take a look at the string[] part and RPCs.
    I can't promise a date but I will take a look asap. We should be able to get rid of that "janky hack" :)
  • Tobias
    Options
    I just tried to reproduce the issue in my (latest) version of PUN and didn't get the issue?!

    [code2=csharp][RPC]
    public void StringRpc(string[] orderedArr, bool[] startingFires, int scenNum)
    {
    Debug.Log("StringRpc() " + string.Join(" ", orderedArr) + " " + startingFires[0] + " " + scenNum);
    }

    // that method can be called just fine by this:
    this.photonView.RPC("StringRpc", PhotonTargets.All, new string[] { "b", "c" }, new bool[] {true, false}, 1);[/code2]


    I don't think my version is much advanced since last release (in terms of RPCs) but maybe something changed even since last release.
    That's good in some way but ... which version are you using?
  • Right now I have 1.20. I'm not sure if I did something weird, it's entirely possible, especially since I'm new to networking and photon. Hmm
  • Tobias
    Options
    Maybe it was some issue with an older PUN version.
    Glad to read it's fixed. Sorry about the inconvenience and good luck.