NetworkVariable write permission

Hello,

I just upgrade this package from develop. Before it’s name is MLAPI, but changed to netcode for gameobjects.
I have question regarding write permission in NetworkVariable.

Before, you can set write and read permission when creating NetworkVariable. But after updating I cannot set write permission anymore. I just see Read Permission.

In the code I just see this function

public virtual bool ShouldWrite(ulong clientId, bool isServer)
{
    return IsDirty() && isServer && CanClientRead(clientId);
}

I think there is no way to set WritePermission unless you create custom NetworkVariable.
Is this the intended workflow?

In the newest implementation they have chosen to remove the ability for clients to change NetworkVariables. You have to use RPC’s instead. You can check the NetworkTransform and Samples/ClientNetworkTransform scripts for a way to implement client writing.

1 Like

Okay, thanks for clarification

What if I wanted to have the client see an instantaneous change to their version of the variable? Am I correct in assuming the best way to do this is to just use an ordinary non-networked variable along with RPCs to sync from client-to-server on value change and vice-versa?

1 Like

Yeah that’s a good way for doing. Use a local variable for your own player, use an RPC which updates a NetworkVariable for the other players.

3 Likes

hi there ! thanks a lot for this!
Trying to implement this for my character movement. Any exemple on how to do it ? been struggling hard…
Thanks a lot

@dilmerval has a video tutorial which might help you out.

Tried this solution but there is still latency on client side.
I would like to have something like this:

if(isOwner)
characterController.Move(velocity * Time.deltaTime);
else
characterController.Move(networkPositionDirection.Value * Time.deltaTime);

Dont know if it makes sense, but i would like the server NOT to update the position on owner…
Please helppp

We published a bunch of educational documents on topics surrounding Lag and Latency.

1 Like