Search Unity

[Command] method prefix

Discussion in 'Multiplayer' started by liortal, Jun 13, 2015.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Hi,

    I was wondering, why is there a requirement to prefix command methods with Cmd, e.g:
    Code (CSharp):
    1. [Command]
    2. public void CmdFire()
    3. {
    4.     // TOO
    5. }
    Is this a technical optimization (find only methods starting with Cmd, instead of iterating over all methods of all types, looking for the attribute) ?

    Also, i wonder why was this attribute called [Command] ? I believe that naming things (even though it's hard) is a very important part of creating APIs, especially ones that are planned to be used by millions of devs.

    Since the Command is a server-side method invocation, any name that signifies this is a server call could've worked better IMHO:
    • [ServerMethod]
    • [ServerCall]
    • [ServerCommand]
    Calling it Command "forces" me as a user to learn how to use it, while having a self-explanatory name makes it a lot easier to understand what it does, even without reading the docs (which are also not always ready early on when we developers have access to the new feature). Just my 0.02$
     
  2. Indiefreaks

    Indiefreaks

    Joined:
    Nov 12, 2012
    Posts:
    89
    I do agree with you. It gets confusing weither you are calling a server method or a client. And it would have been great if UNET could have come up with some consistency in the naming of things. It's kinda hard on a single eye shot to see what is the difference between just Command and Server attributes or even worse ClientRPC,Client, ClientCallback ones...

    Maybe a bit over engineered here with some future developments in mind.

    For my own High Level Networking system I implemented back then when developing on XNA, I named things like so:
    LocalCommand, ClientCommand, ServerCommand.
    With that at least you know where it'll get executed :p