Search Unity

Question NetworkVariable write permission

Discussion in 'Netcode for GameObjects' started by firaui, Sep 30, 2021.

  1. firaui

    firaui

    Joined:
    Nov 14, 2018
    Posts:
    12
    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
    Code (CSharp):
    1. public virtual bool ShouldWrite(ulong clientId, bool isServer)
    2. {
    3.     return IsDirty() && isServer && CanClientRead(clientId);
    4. }
    I think there is no way to set WritePermission unless you create custom NetworkVariable.
    Is this the intended workflow?
     
  2. SorenSaket

    SorenSaket

    Joined:
    Apr 3, 2015
    Posts:
    1
    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.
     
  3. firaui

    firaui

    Joined:
    Nov 14, 2018
    Posts:
    12
    Okay, thanks for clarification
     
  4. Chrispins

    Chrispins

    Joined:
    Dec 9, 2014
    Posts:
    15
    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?
     
    insoluzioni likes this.
  5. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
    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.
     
    Oberheim, insoluzioni and Chrispins like this.
  6. Oberheim

    Oberheim

    Joined:
    Jun 4, 2020
    Posts:
    24
    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
     
  7. CreativeChris

    CreativeChris

    Unity Technologies

    Joined:
    Jun 7, 2010
    Posts:
    457
  8. Oberheim

    Oberheim

    Joined:
    Jun 4, 2020
    Posts:
    24
    Tried this solution but there is still latency on client side.
    I would like to have something like this:

    Code (CSharp):
    1. if(isOwner)
    2. characterController.Move(velocity * Time.deltaTime);
    3. else
    4. 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
     
  9. CreativeChris

    CreativeChris

    Unity Technologies

    Joined:
    Jun 7, 2010
    Posts:
    457
    Wilhye likes this.