com.unity.netcode.gameobjects
com.unity.netcode.gameobjects copied to clipboard
Add a system to tag methods so they can only be executed either client-side or server-side
In my code (and I would guess that is the case for many other users), I have, for a bunch of my mehtods executed only server-side, the following snippet of code:
if (!NetworkManager.Singleton.IsServer)
{
return;
}
I have the same, with IsClient, for my methods only executed client-side. This system is heavy and error prone: I have to add this snippet manually every time and might forget to do it sometimes.
I believe Mirror has [Server] and [Client] decorators on methods, I'm guessing they're doing what I'm talking about. I think the relevant documentation page is https://mirror-networking.com/docs/api/Mirror.ClientAttribute.html .
I would love to see this feature added to Network for GameObjects, which would make our code both clearer and more stable.
Me too ! 😍
They seems to use Unity's internal ILPostProcessor to do code weaving.
https://github.dev/vis2k/Mirror/blob/1631402bd7cad3f349f12a4e0d4eb82821c382a9/Assets/Mirror/Editor/Weaver/EntryPointILPostProcessor/ILPostProcessorHook.cs#L139
https://forum.unity.com/threads/how-does-unity-do-codegen-and-why-cant-i-do-it-myself.853867/