Search Unity

Question Creating a "Command Channel" Client to control a Netcode Host

Discussion in 'Netcode for GameObjects' started by VRS3DGuru, Apr 15, 2023.

  1. VRS3DGuru

    VRS3DGuru

    Joined:
    Sep 21, 2017
    Posts:
    14
    Command Client would be a dedicated client that only passes control commands to the host. This would not be a standard networked player. IE this command client would connect to the host via NetCode, but the scene on this client would never change. It could "command" the host to change scenes on all clients via ServerRPC, except that the command client would not change scenes, it would stay in the command client scene with a command UI used to control the HOST. When building the Command Client, only one scene would be in the command client's build list, the command UI scene. All other clients and host would have complete build lists with all scenes included.

    Question - how do we get the command client to "ignore" or not participate in the Netcode network scene management load scene method call? We do want the Host (player as host) and the Clients (player as client) to all change scenes, but not the Command Client. It is sufficient to simply only have one scene in the build list at the time of building the Command Client and have the server ignore a lack of callback from this specific client on scene loads, etc? This command Client would also not have all of the same in scene game objects nor the same NetSyncVars in its scene, it would only have a special set of game objects, components to provide the command UI functionality. Any thoughts?
     
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    You can either use custom scene management, or pur the command client in the same scene of the other ones but hiding all the "non-relevant bits". Option 2 is probably easier.

    Does this help?
     
  3. VRS3DGuru

    VRS3DGuru

    Joined:
    Sep 21, 2017
    Posts:
    14
    thank you, custom scene management seems like a very challenging under-taking after looking into it.

    Another idea was to leverage Unity Netcode scene management with default features but allow only the command client to not have to validate scene management with the host. Would there be a way to have this command client only have a command UI in its scene, stay in that scene once the host starts, have components in the host, etc to receive commands from this client IE same command UI component but hidden on the host? So in this approach the host and all other clients would have complete scene but the controller UI client would only have the UI components. This would prevent having to build and redistribute runtime builds to the controller. Think of this like an AV controller in a meeting room, we just want a lightweight UI on it to control netcode based experiences running in the room via netcode native framework but in the easiest manner possible.
     
  4. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi just asked this internally to the Netcode team, will get back at you as soon as I have a valid answer
     
  5. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    259
    Hello @VRS3DGuru,
    This is possible but there are a few methods you will want to look into using:
    You should should keep in mind that when a client connects and the connection is approved, it will be synchronized with all spawned NetworkObjects. This means the client will need to "know" how to handle the spawning process for those NetworkObjects. If you have in-scene placed NetworkObjects but don't load the scene, then this can cause issues.

    Without knowing how your project is setup and all of the specifics (how many scenes, of those scenes how many in-scene placed NetworkObjects, etc), some of the next recommendations you will have to determine if they work for your project. I would highly recommend reading through the object spawning documentation first.

    Since in-scene placed NetworkObjects are a bit of a conundrum to handle (for this scenario) you might think about converting any in-scene placed NetworkObjects over to a Dynamic Spawned (non-pooled) in-scene placed NetworkObject (also read a bit about the "Hybrid Approach" example). In-Scene placed NetworkObjects are convenient in that you can easily configure its settings via the inspector view, but for your scenario you would need to make any in-scene placed dynamically spawned NetworkObject use a ScriptableObject to uniquely configure it or for a more advanced approach handle serializing the "unique properties" via NetworkBehaviour.OnSynchronize. The reason behind the "Hybrid Approach" for your in-scene placed NetworkObjects is that once the associated network prefab is spawned it is synchronized like a dynamically spawned NetworkObject (because it really is being dynamically spawned). The advantage to this is that the network prefab being spawned just has to be registered in the prefab list and doesn't actually have to exist in the scenes (that your command client isn't going to load).

    The final thing to consider is using a unique NetworkManager configuration for the command client where you might want to create network prefab overrides that point to "place holder replacement" network prefabs that might not have all of the assets required (i.e. could just be a GameObject with NetworkObject).

    You will also want to handle object visibility (really this means "Network Visibility") on the server side where you can make certain NetworkObjects "not visible" to the command client so it doesn't receive messages (i.e. you have an override network prefab that doesn't have the NetworkBehaviours with RPCs and/or NetworkVariables on the command client so you don't want to try and send RPCs or NetworkVariable updates for any instance of that network prefab to the command client).

    With all of this said, this should get you pointed in the right directions and you can post any questions you have about the above (or issues you run into here).
     
  6. VRS3DGuru

    VRS3DGuru

    Joined:
    Sep 21, 2017
    Posts:
    14
    Some of this makes sense, some of it I will have to go research and Digest, will have to get smarter on the network manager and spawning. thank you very much, both of you, for this input!