Network Weapon
Network Weapon syncs the server’s weapons to the other clients. Place it on the root of a network prefab, next to its NetworkObject. It finds every Weapon in the children.
Note
The root must be active when the object spawns. Netcode skips network components on inactive objects, which is why this goes on the root and not on each weapon.
✅ Ideal For
- Players with one weapon
- Players that switch between several weapons
- Weapons that swap barrels or magazines at runtime, such as
DualWeaponandUpgradableWeapon
📐 Inspector Overview
It has no settings. It works with the child weapons it finds.
⚙️ How It Works
flowchart LR
S["Server weapon"] -->|"weapon, barrel, magazine, trigger"| N["Network Weapon"]
N --> C["Client weapon copy"]
- Every frame on the server, it reads the active weapon: the first child
Weaponthat is active and enabled. It syncs its index, its current barrel and magazine, and whether its trigger is held. - When the trigger changes, the other clients set the same barrel and magazine on their copy and pull or release its trigger. Their copy fires like the server’s.
- When the server switches weapons, the old weapon stops on the clients too.
- The owner skips the server’s trigger. It fires its own copy as soon as it sends its input, so shooting feels instant.
- Switching which weapon is shown is up to your game (for example a weapon cycler synced by your input script).
Network Weapononly fires the weapon a client already shows.
Client copies still hit things, so you see impacts and hit effects, but Network Health blocks their damage. Only the server’s hits count.
🧩 Scripting
| Member | Description |
|---|---|
activeWeapon | The first active and enabled child Weapon, or null |
Pull(Weapon) | Called on a client when the server’s trigger is pulled. Override it to mirror custom weapon logic |
Release(Weapon) | Called on a client when the server’s trigger is released |