Passing a Network Variable onto a parameter

Newbie here, I just want to know if I can pass a variable to a method to change its value so that I wont have to create multiple methods for each Network Variable

This is how I tried to do it:

    [ServerRpc(RequireOwnership = false)]
    private void ValueChange_ServerRpc(float NetVar, float newValue) {
        NetVar = newValue;
    }

What am I doing wrong here?

Writing nonsensical code. :stuck_out_tongue:

Both values are passed into the method by value. You assign one value to another. Nothing happens beside NetVar having the same value as newValue WITHIN the current method.

To use NetworkVariable check the manual. You’re supposed to assign to the Value property of an instance of NetworkVariable, it synchronizes automatically.

1 Like

Depending upon what you are trying to accomplish, you could also just use a struct that implements INetworkSerializable. This way you can set many properties (defined in your struct) at once and use that struct with an RPC or NetworkVariable (depending upon how you want the values to update and propagate).

1 Like

I was under the impression that I can just do that since it wont let me use ref on a network variable… oh well, newbie mistake I guess.

Im still in the process of learning C# and Unity so Im still a bit clueless when it comes to some of these things.