Mirror Plumber

YAPYAP MirrorPlumber

Utility BepInEx Mod for Mirror Networking in YAPYAP.

Mirror Plumber is a utility library that allows modders to easily create and use new Mirror NetworkActions, including Commands, ClientRpcs, and TargetRpcs, without manually wiring Mirror’s internal RPC plumbing.

It is designed to simplify multiplayer mod development and eliminate the boilerplate and error-prone setup normally required when working with Mirror outside of Unity’s normal build pipeline.

Core Features

  • Automatic plumbing for:
    • Commands
    • ClientRpcs
    • TargetRpcs
  • No manual RPC registration required
  • Works with AssetBundle-loaded NetworkPrefabs
  • Multiplayer-safe and deterministic
  • Clean, explicit API for invoking network actions
  • Supports parameters and authority checks

Mirror Network Prefabs

Creating a Network Prefab

  • Create a GameObject that will serve as your Network Prefab.
  • Add a NetworkIdentity component (required).
  • Attach your class inheriting from NetworkBehaviour.
    • This can be done in Unity or at runtime.
  • Do not add NetworkIdentity at runtime.
    • The assetId will not be assigned properly.

After setup build the prefab into an AssetBundle.

Loading Your Network Prefab

  • At Plugin Awake:
    1. Load your AssetBundle.
    2. Load your GameObject.
    3. Add any required NetworkBehaviour components (if not pre-attached).
    4. Cache the GameObject reference.
  • At Plugin Start (before hosting):
    1. Call NetworkClient.RegisterPrefab(GameObject)
    2. Cache the assetId using:
      GetComponent<NetworkIdentity>().assetId
      

       

Spawning the Network Prefab

After the server is active:

  1. Instantiate your cached GameObject.
  2. Call NetworkServer.Spawn(instance, cachedAssetId)
  3. Only spawn from the server client.

Where MirrorPlumber Comes In

Without MirrorPlumber:

  • [Command], [ClientRpc], [TargetRpc] will not function automatically.
  • You must manually register every network delegate using:
    • RemoteProcedureCalls.RegisterDelegate
    • RemoteProcedureCalls.RegisterRpc
    • RemoteProcedureCalls.RegisterCommand

Using MirrorPlumber

Create Static Plumber References

You will invoke these manually, so store references:

internal static Plumber GeneratedCommand = null!;
internal static Plumber<string, int> GeneratedRPC = null!;

Create Plumbers (Recommended in Awake)

Plumber constructor parameters:

  • System.Type netBehaviour
    Example: typeof(MyNetworkBehaviour)
  • string methodName
    Example: nameof(MyNetworkedMethod)
  • NetType netType
    (Command, ClientRpc, TargetRpc)
  • bool requiresAuthority = false (optional)

You must create a Plumber before invoking a NetworkAction.

Register Listeners

Use AddListener() to define what runs when the action is received.

Multiple listeners are allowed, provided parameter signatures match.

Example:

private void Awake()
{
    GeneratedCommand = new(typeof(NetworkingTestWithPlumbing),
        nameof(CmdSendHello),
        PlumberBase.NetType.Command);

    GeneratedCommand.AddListener(RpcShowHelloMessage);

    GeneratedRPC = new(typeof(NetworkingTestWithPlumbing),
        nameof(RpcShowHelloMessage),
        PlumberBase.NetType.TargetRpc);

    GeneratedRPC.AddListener(HelloFromTheNetwork);
}

Invoke the Plumber

Instead of calling your RPC method directly, invoke the Plumber.

Recommended: use null-conditional operator.

Examples:

GeneratedCommand?.Invoke(this);

GeneratedRPC?.Invoke(
    this,
    "Hello World from the network!",
    1337,
    NetworkServer.connections[0]
);

Invoke Parameters

  • TSource instance → Your NetworkBehaviour instance
  • NetworkConnection target (TargetRpc only)
  • Additional parameters → Data being sent

These calls must be made from non-static methods inside your NetworkBehaviour.

Official Github page.

Requires: BepInEx 5

Made by: darmuh

How to Install

  1. Install BepInEx if it is not yet installed.
  2. Download and unzip MirrorPlumber to YAPYAP\BepInEx\plugins

If you have any problems installing this or any other mod for YAPYAP, read this guide.

Downloads

Leave a Reply

Your email address will not be published. Required fields are marked *