Search Unity

Should UI be spawned to be able to use [Cmd]?

Discussion in 'Multiplayer' started by Chom1czek, Aug 20, 2016.

  1. Chom1czek

    Chom1czek

    Joined:
    Sep 19, 2015
    Posts:
    66
    I'm a little bit confused about connecting UI & UNET.
    To use [Command] and other Networking things we need to derive from NetworkBehaviour but if I create UI runtime do I need to use Network.Spawn or SpawnWithClientAuthority to be able to use [Commands] and stuff? Or just extending NetworkBehaviour is enough to do so?

    Cheers
     
  2. isidro02139

    isidro02139

    Joined:
    Jul 31, 2012
    Posts:
    72
    Hey @Chom1czek – in my experience it's better not to have your UIs inherit from NetworkedBehavior, there was a discussion about this recently at unitydevs.slack.com in the #networking channel.

    UIs should just present information / accept input so as not to violate the Single Responsibility Principle.

    Arun
     
  3. Chom1czek

    Chom1czek

    Joined:
    Sep 19, 2015
    Posts:
    66
    Thanks for the answer @isidro02139 but I am trying to implement MVC/MVP pattern into my project so my UI should only do input/out, at least I am trying to do so but I need to somehow connect it with sending [Commands] to the server, if you have any better idea then I am listening :)

    Cheers

    Chom1czek
     
  4. isidro02139

    isidro02139

    Joined:
    Jul 31, 2012
    Posts:
    72
    I recommend making manager objects (like in most of the official unet tutorials) and calling network methods via that class. Then your UI can be purely input/output. It's also a good abstraction layer incase the networking API or solution you use changes.

    Arun