- Home /
How [Command] and [ClientRpc] are made in that way that when you call them they notify the network to send the parameters but the code inside doesn't get executed.
I make my own HLAPI, everything works perfectly but I don't know how they managed to create methods with a behaviour like this.
Answer by Bunny83 · Mar 14, 2021 at 03:01 AM
They used an IL post processor which they called the UNetWeaver which does actually replace the calls to your method depending on the role. So the ordinary method call is replaced by some extra code that actually does determine what to do. I'm not sure if they used the Mono.Cecil library which can be used to inspect and alter compiled IL code. Unity's UNetWeaver is of course specialized for the UNet system. There are other generic weaver solutions out there. However that topic is quite advanced.
The Command and ClientRpc attributes are just attributes. Attributes do not do anything on their own. They are just metadata that is stored along with the actual class / member / parameter. So there's always an external system that interprets that metadata. Common examples are the Serializable attribute which is often required by serializers. Though there are some attributes that are actually interpreted by the compiler during compile time. Some examples are "AttributeUsage" or "Conditional". So Unity's UNetWeaver actually post processes the compiled assembly and replaces the method calls with the appropriate code.
Thanks, then I use the method I created. The syntax isn't as good as uNet, but it allows me to connect to multiple hosts at the same time and get rid of some rules that I don't think are necessary. I used to think that those who develop their game on the Low Level API waste their time, but after a long time with the High Level API I realized that their Network Manager is not so universal and is not designed for all games. Thanks again for the answer.
Your answer
Follow this Question
Related Questions
Object not updating on host 1 Answer
[Command] not being called by clients 0 Answers
Network how to send data/activate function 1 Answer
Player Doesn't Exist On Client 0 Answers
Why is the command function not being called on the client? 0 Answers