Issue modifying variables with an RPC.

I am calling an RPC with an integer parameter and I can see that I am successfully receiving it. However, when I try to set a variable within the RPC, it seems to not be working as I expect.

I this example, the rpc is called with 2 as the integer being passed.

int num = 1;

void Update()
Debug.Log("The number is: " + num); // Always says "The number is: 1"

void TestRPC(int x)
Debug.Log ("x: " + x); // "x: 2" as expected
num = x;
Debug.Log ("num: " + num); //"num: 2" as expected

Everything looks fine with the log messages within the TestRPC method, but in Update num is not changed to 2 but is always 1.


  • Maybe you have an another script who call num = 1; in a Update() loop

    tro to change your int num = 1; to int numtest = 1;

    If an another script try to access at your int num, you will get an error.
  • Thank you for that tip rokawar; I wish I would have tried that. I ended up rewriting a large part of the code and don't seem to have the problem anymore with any of my new RPCs. I'm not sure where my mistake was but it had to be something like you suggested where the value was being changed somewhere else. I remember checking to see if the variable was being accessed elsewhere but I must have missed it.
Sign In or Register to comment.