0
\$\begingroup\$

[Command] and [Server] functions both run on the server and can also be called by a local player but what is the difference between them?

\$\endgroup\$
  • 1
    \$\begingroup\$ I'm not 100% sure myself, but I do know that [COMMAND] attribute is only for use on PLAYER controlled objects. That might be something to do with it (I'm also learning Unity Network gaming ~gradually~ at the moment :] \$\endgroup\$ – Big T Larrity Nov 22 '18 at 12:52
  • 2
    \$\begingroup\$ It may not be advisable to learn UNet too deeply, it is being deprecated and replaced in the next six to 12 months. \$\endgroup\$ – Draco18s Nov 22 '18 at 15:19
  • \$\begingroup\$ @SuperMegaBroBro Yeah it may help to understand. \$\endgroup\$ – Abhinay Singh Negi Nov 25 '18 at 3:28
  • \$\begingroup\$ @Draco18s I'll keep in mind. \$\endgroup\$ – Abhinay Singh Negi Nov 25 '18 at 3:30
1
\$\begingroup\$

They actually do quite different things according to the documentation:

https://docs.unity3d.com/ScriptReference/Networking.CommandAttribute.html

[Command] functions are invoked on the player GameObject associated with a connection

https://docs.unity3d.com/ScriptReference/Networking.ServerAttribute.html

A [Server] method returns immediately if NetworkServer.active is not true, and generates a warning on the console

But be sure to be mindful of the comment by Draco18s:

It may not be advisable to learn UNet too deeply, it is being deprecated and replaced in the next six to 12 months

\$\endgroup\$
  • \$\begingroup\$ I'll keep in mind what @Darco118s said. But I wanted to know that [Command] is called by the player object, but who calls [Server] function. \$\endgroup\$ – Abhinay Singh Negi Nov 25 '18 at 3:42
  • 1
    \$\begingroup\$ I don't think it matters who or what calls a [Server] attribute. The way I understand it is that you wanna use the [Server] attribute for any function that absolutely has to be connected to the server. \$\endgroup\$ – HappyGuyDK Nov 25 '18 at 10:18
  • \$\begingroup\$ @HapppyGuyDk Ok \$\endgroup\$ – Abhinay Singh Negi Nov 25 '18 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.