[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?
-
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 LarrityCommented Nov 22, 2018 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 no longer trusts SECommented Nov 22, 2018 at 15:19
-
\$\begingroup\$ @SuperMegaBroBro Yeah it may help to understand. \$\endgroup\$– Abhinay Singh NegiCommented Nov 25, 2018 at 3:28
-
\$\begingroup\$ @Draco18s I'll keep in mind. \$\endgroup\$– Abhinay Singh NegiCommented Nov 25, 2018 at 3:30
1 Answer
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
-
\$\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\$ Commented Nov 25, 2018 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\$ Commented Nov 25, 2018 at 10:18
-