Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Documentation outdated?

Discussion in 'Netcode for GameObjects' started by Kyperr, Jan 14, 2022.

  1. Kyperr

    Kyperr

    Joined:
    Jul 15, 2016
    Posts:
    31
    Can you no longer set permissions to allow clients to write to network variables as stated here?
    https://docs-multiplayer.unity3d.com/docs/basics/networkvariable#permissions

    Is the only way now to use a server rpc? If so, it seems like now there's unnecessary work if you want to not create lag from a round-trip for things such as position. If I want to have no lag, I'd need a local position and a network variable position, it seems.
     
  2. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    306
    Yes the docs are out of date. See my answer here.

    And yeah you're right you could achieve a similar result with a local position variable + a NetworkVariable + an Rpc to change the NetworkVariable whenever your localposition changes and then drive the position from the local variable for the owner and from the NetworkVarialbe for everyone else.
     
  3. Kyperr

    Kyperr

    Joined:
    Jul 15, 2016
    Posts:
    31

    Understood. I'll probably abstract this pattern into something like a ClientControlledNetworkVariable that encapsulates the ServerRpc bevavior.

    Though this feels like I'm simply recreating something that was purposefully removed from the library. I full trust the developers, so I'm questioning if this is actually a good idea, or if there is a reason to Not use this pattern.
     
  4. Kyperr

    Kyperr

    Joined:
    Jul 15, 2016
    Posts:
    31
    ... Or not. I couldn't find an efficient way to make this work. I wanted to simply extend NetworkVariable and add a ServerRpc, but I couldn't find a way to inject into the Rpc pipeline from a class that would otherwise not be able to run a ServerRpc.

    I'm sure I could add my own custommessanger logic, but that might be more work than I'm interested in just to avoid having to write ServerRpcs everywhere.

    Is there a way to run ServerRpc's outside of NetworkBehaviors?
     
  5. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    306
    There is an RFC up to add client network variables back and from what I understand the idea is similar to what you planning to do with having a ServerRpc inside the NetworkVariable. RPCs currently have to be defined on a NetworkBehaviour but they can be called from anywhere. So you'd still need to define an RPC for every "ClientControlledNeworkVariable".

    I suggest commenting on the RFC as that will reach the developers which are working on this.
     
  6. Kyperr

    Kyperr

    Joined:
    Jul 15, 2016
    Posts:
    31
    Thanks Luke. I was not careful with my wording, but that's what I understood to be true. I was hoping there was a way to register them from outside of the NetworkBehavior. I've done similar things with method proxies (I assume RFCs are method proxies) in Java's spring so I was hoping it was possible.

    That RFC is exactly what I'm looking for and I'm excited to follow it. Thank you!
     
unityunity