Dev Tools
There are several networking tools available, depending on your use case. Some are patchers, while others are APIs to help ease networking.
Patchers
There are two main patchers available to use. The first and preferred is performed during/shortly after compilation of the mod. The second runs alongside and patches your mod during runtime.
UnityNetcodePatcher
First, and the most supported, is UnityNetcodePatcher. This patcher runs Netcode for GameObjects' (NGO) post-processing on your code. This is the "native" way of networking that the game uses.
Installing UnityNetcodePatcher
- Add the following code to your
Plugin::Awakemethod:
private void Awake()
{
var types = Assembly.GetExecutingAssembly().GetTypes();
foreach (var type in types)
{
var methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
foreach (var method in methods)
{
var attributes = method.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), false);
if (attributes.Length > 0)
{
method.Invoke(null, null);
}
}
}
}- Install the tool with:
$ dotnet tool install -g Evaisa.NetcodePatcher.Cli- Add the following code to your
.csproj:
<Target Name="NetcodePatch" AfterTargets="PostBuildEvent">
<Exec Command="netcode-patch -uv 2022.3.62 -nv 1.12.0 -tv 1.0.0 "$(TargetPath)" @(ReferencePathWithRefAssemblies->'"%(Identity)"', ' ')"/>
</Target>Editing the .csproj
To modify the .csproj file, there are a few different methods possible. The first option is to open the file in a text editor - such as Notepad++. You can also modify the file in your IDE, which can be opened by either pressing F4 when the project is selected in the solution explorer, or by right-clicking the project in the solution explorer and selecting Edit Project.
Updating UnityNetcodePatcher from before v73
If you previously used Unity Netcode Patcher or have it installed, before patching for v73 and later, ensure you have the latest version of UNP.
The maintainer of that project recommends uninstalling and reinstalling the package globally to ensure there's not conflicting files and is up-to-date:
$ dotnet tool uninstall -g Evaisa.NetcodePatcher.Cli
$ dotnet tool install -g Evaisa.NetcodePatcher.CliAdditionally, ensure you are using the CLI/post-build event correctly with the new parameters:
$ netcode-patch -uv 2022.3.62 -nv 1.12.0 -tv 1.0.0 ...<Target Name="NetcodePatch" AfterTargets="PostBuildEvent">
<Exec Command="netcode-patch -uv 2022.3.62 -nv 1.12.0 -tv 1.0.0 "$(TargetPath)" @(ReferencePathWithRefAssemblies->'"%(Identity)"', ' ')"/>
</Target>TIP
Currently, this is the only patcher that has support for Network Variables. If you intend on using those, and do not intend on using an API, you will have to use UnityNetcodePatcher.
StaticNetcodeLib
Second, with a different use case, is StaticNetcodeLib. This patcher will patch your remote procedure call (RPC) methods at runtime.
The main difference between this patcher and the others is the support (only) for static RPCs. This allows you to quickly do networking in a static or singleton-like way, reducing the need for the code required to allow you to use RPCs. In other respects, the RPCs work almost exactly like NGO.
To install and use StaticNetcodeLib, look at the corresponding wiki article.
APIs / Libraries
There is currently only one networking-specific library available, shown below.
LethalNetworkAPI
LethalNetworkAPI is meant to provide easier methods of networking, particularly in a more static-like nature. Instanced networking, however, is also supported. This API also supports NetworkVariables, if you intend on using them.
For documentation, look at LethalNetworkAPI's wiki.