Getting Started

🧠 How It Works

The server runs the real game. Clients send their input and show what the server decides.

  flowchart LR
    A[Owner input] -->|RPC| B(Server)
    B --> C{Weapon fires}
    C -->|hits| D[Health changes]
    B -->|NetworkWeapon| E[Clients fire their own copy]
    D -->|NetworkHealth| F[Clients show the new health]
  • The owner fires its own copy of the weapon right away, so shooting feels instant, and sends the input to the server.
  • The server fires the real weapon. Only its hits change health.
  • Other clients get the server’s trigger through Network Weapon and fire their own copy, so everyone sees the same shots.
  • Health is synced by Network Health. Client hits only show effects.

All scripts are in the GlowingRifts.MultiplayerModularWeaponSystem namespace. The example scripts are in GlowingRifts.MultiplayerModularWeaponSystem.Example.

📦 Installation

Import the packages

Import the Modular Health System and the Modular Weapon System, then this package. It is installed under Assets/Glowing Rifts/Multiplayer Modular Weapon System.

Install the Unity packages

In the Package Manager, install Netcode for GameObjects 2.x and Multiplayer Services.

Link Unity Cloud

The lobby uses Unity Multiplayer Services (Lobby and Relay). Link your project to a Unity Cloud project in Edit > Project Settings > Services.

Add the scenes to the build

Add Examples/Lobby/Lobby, Examples/DuckShooter_Multiplayer and Examples/Blueprint_Multiplayer to your build scene list, with the Lobby first.

Play

Open the Lobby scene and press Play. To test several players on one computer, open Window > Multiplayer > Multiplayer Play Mode and turn on more players.

🔫 Making a Weapon Work Online

Make a network prefab

Make a prefab variant of your player (or any object holding weapons) and add a NetworkObject to its root, plus a NetworkTransform if it moves.

Add Network Weapon

Add Network Weapon to the same root. It finds every child Weapon, so one component covers all the weapons the player carries.

Send the input

Turn off the weapon’s built-in input. Write a small NetworkBehaviour that, on the owner, pulls its own trigger and sends the input to the server with an RPC. On the server, call StartShooting and StopShooting on the weapon. The example NetworkPlayerInput and BPNetworkPlayerInput scripts do this.

Add Network Health

If the player can be hit, add Network Health next to its Health, and turn off Destroy On Death on the Health.

Register the prefab

Add the prefab to the network prefab list of your NetworkManager.

🚀 Projectiles

  • Raycast, laser and straight projectiles don’t need anything: every machine fires its own copy and only the server’s hits count.
  • Physical or homing projectiles (grenades, rockets) can land in different places on each machine. Make a network variant of the ammo prefab with a NetworkObject, a NetworkTransform and Network Auto Spawn, and list the ammo script as server only. Do the same for the effect it creates on impact, such as an explosion.

Tip

Netcode skips network components on objects that are inactive when they spawn. Keep NetworkWeapon and your input script on the root, which is always active.