Do RPC functions affect variables outside the RPC function?

It appears to be a straight forward question but can RPC functions affect variables outside the RPC function?

Everything works fine on the computer that first sends out the RPC.

I’ve read countless networking tutorials and all of the docs pertaining to this but I feel as if I’ve missed something important. I have an RPC function that is .All and it will instantiate the item I want and apply the correct force on all machines plus the Debug.Log in the RPC gets displayed fine but it will not affect a counter variable I have, except in that specific RPC function.

I have “if (counter > 0)” in my FixedUpdate that I’m attempting to use. In the RPC function I have a counter++ that actually increases the counter(debug.log proves this), but when it checks it in the FixedUpdate, it is back to it’s original 0. What appears to be even stranger is that the next time I call the RPC function, the counter get’s raised and the Debug.Log reflects this, so the second time through the function it shows that the counter is now 2, but just like before, in the FixedUpdate, the counter is 0 again. What is going on?

Thank you for your time.

Counter is declared at the top of the script above all classes. Besides that, these are all the times that counter appears in the script.

The RPC function is called within flingPoo() if certain variables are set to true. I recently took out all non counter code to make it more condensed for easy viewing. Same errors on my end.

Pertinent code:

networkView.RPC(“Fire2”, RPCMode.All, transform.position, power, angle);

@RPC
function Fire2(position1: Vector3, power1: float, angle1: float)
{
	counter++;
	Debug.Log("c " + counter);
}
function FixedUpdate() 
{
	Debug.Log("counter " + counter);
	FlingPoo();
}

First it would be interesting how and where your counter variable is defined. Next thing is are you sure that this is the only place where you manipulate / set the variable? A common mistake is using the assignment operator (=) instead of an equality operator(==) inside an if statement.

To find all places where your counter variable is changed there are multiple ways. If you use MonoDevelop you usually should be able to rightclick on the counter variable name and choose “Find All References”. This should show you a list of all code fragments which use the variable.

In C# i would temporarily replace the counter variable by a property with an Debug.Log statement in it’s setter. This way you can exactly see who is changing the variable and when.

Short answer is yes.

Longer explanation is that I had two instances of the player which both had a “FIRE2” function so it would only call it on one. I made the counter variable static and it works. I’m fairly certain this is the wrong way to do it but I’m still learning and it works.