Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Help Wanted Where are the NetworkVariableSettings

Discussion in 'Netcode for GameObjects' started by niekzandt, Nov 7, 2021.

  1. niekzandt

    niekzandt

    Joined:
    Sep 2, 2018
    Posts:
    3
    Hey everyone,
    In 1.0.0 the way networkvariables worked was changed. I want to change the write permissions of my NetworkVariables, documentation says I can do this through NetworkVariableSettings like so:
    Code (CSharp):
    1. private NetworkVariable<float> myFloat = new NetworkVariable<float>(new NetworkVariableSettings {WritePermission = NetworkVariablePermission.OwnerOnly}, 5);
    However this doesn't seem to work and it says NetworkVariableSettings doesn't exist. If I look inside of NetworkVariable I can't find anything similar to it either. The documentation was updated on the day of the update. If someone could help me out with this it would be great!
     
  2. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    255
    There are no NetworkVariableSettings anymore. Only the server can write to NetworkVariables in the 1.0.0 version.
     
  3. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    255
    You are right the docs page is out of date, will update it asap.
     
    mateuszwallace likes this.
  4. mateuszwallace

    mateuszwallace

    Joined:
    Dec 13, 2019
    Posts:
    4
    "By default NetworkVariable and its subclasses can only be written to by the server (NetworkVariablePermission.ServerOnly). To change that set the permission to the desired value during initialization:"
    So still the problem exist this documentation have to updated. If in the documentation are more misleading informations creating a multiplayer game with netcode will be nearly impossible.
     
  5. nitrogendragon

    nitrogendragon

    Joined:
    Sep 13, 2017
    Posts:
    4
    How do we go about writing to the networkVaraible then when a client clicks on a button for example to change their teamId and update its color? I'm just confused and stressed from trying to get things working so sorry if this was answered already in a different thread. Thanks for any help in advance.
     
  6. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    118
  7. nitrogendragon

    nitrogendragon

    Joined:
    Sep 13, 2017
    Posts:
    4
  8. BinaryVector

    BinaryVector

    Joined:
    Sep 2, 2018
    Posts:
    1
    I am assuming you are also following Dapper Dino's tutorials. I was stuck on the same place, and after realizing that the NetworkVariableSettings have been removed, I tinkered around and ended up with the following code snippet. In my SelectTeam(int userIndex) method, right above I added these lines:

    Code (CSharp):
    1. if(!NetworkManager.Singleton.IsHost)
    2. {
    3.  
    4. if(!NetworkManager.Singleton.LocalClient.PlayerObject.TryGetComponent<ScriptWithServerRpcFunction>(out ScriptWithServerRpcFunction teamChange))
    5. {
    6. return;
    7. }
    8.  
    9. teamChange.SetTeamServerRpc((byte)userTeamIndex);
    10. }
    It worked for 2 clients + 1 host for me. Hopefully this is useful to you. If you are not following that tutorial, the general idea I worked out here was if we are not a host, then can I directly access my local client's components without having to use the ConnectedClients property (in my case that was the error I was getting: "NotServerException: ConnectedClients should only be accessed on the server.").

    Edit: Messed up indentation haha, sorry.
     
    Last edited: Jan 1, 2022
  9. nitrogendragon

    nitrogendragon

    Joined:
    Sep 13, 2017
    Posts:
    4
    Yep, followed dapperdino and now I'm confused because of the updates to netcode. they really need to fix the documentation up so an average human(me) can understand what everything does and doesn't do. Also though don't really get why they removed functionality, its clearly much more complicated to do anything now if my constant failures to update across host and clients is any indication.
     
    BinaryVector likes this.
  10. Mariiooo

    Mariiooo

    Joined:
    Sep 4, 2019
    Posts:
    6

    I have the same problem. I also found in every documentation that you can access the NetworkVariableSettings.. I'm also a newbie.. I hope they fix it soon.
     
unityunity