xgaming.tools

s&box Network Events Reference

Searchable cheatsheet for s&box's INetworkListener and INetworkSpawn — OnConnected, OnDisconnected, OnActive, OnNetworkSpawn — with copy-ready C# implementations sourced from the official Facepunch docs. Essential for first-time s&box dedicated server developers.

Called on the host when a client has just connected to the server. They are about to start handshaking — they will load the game and download all required packages next. The player isn't fully in yet; don't spawn anything for them here.

Fires before the client has finished loading. Wait for OnActive before spawning the player.

Example
public void OnConnected( Connection connection )
{
    Log.Info( $"{connection.DisplayName} connected — handshaking..." );
}

Called on the host when a client is fully connected and has completed the handshake. After this call they will close the loading screen and start playing. This is the right place to spawn the player object and assign ownership.

Most commonly the player-spawn hook. Always called after OnConnected.

Example
[Property] public GameObject PlayerPrefab { get; set; }
[Property] public GameObject SpawnPoint { get; set; }

public void OnActive( Connection connection )
{
    var player = PlayerPrefab.Clone( SpawnPoint.Transform.World );

    // Optional: read a NameTag component if your prefab has one.
    var nameTag = player.Components.Get<NameTagPanel>(
        FindMode.EverythingInSelfAndDescendants );
    if ( nameTag is not null )
    {
        nameTag.Name = connection.DisplayName;
    }

    // Spawn it on the network and assign the connection as the owner.
    player.NetworkSpawn( connection );
}

s&box Network Events

Game logic in s&box reacts to network state by implementing one of two interfaces on a Component placed in the scene: Component.INetworkListener for connection events (OnConnected, OnDisconnected, OnActive) or Component.INetworkSpawn for the per-object spawn event (OnNetworkSpawn). The methods are optional — implement only the ones you care about.

OnConnected vs OnActive

The two are easy to confuse. OnConnectedfires the moment a client opens the connection — they haven't loaded the game yet, packages are still downloading, and they can't see anything. OnActive fires once the handshake is complete and the loading screen has closed; this is when you should spawn the player objectand assign ownership. Don't try to do that in OnConnected— the client isn't ready to receive it.

Full GameNetworkManager Example

Drop-in network manager
using Sandbox;

// Implement INetworkListener on a Component placed in the scene to react to lobby events.
public sealed class GameNetworkManager : Component, Component.INetworkListener
{
    [Property] public GameObject PlayerPrefab { get; set; }
    [Property] public GameObject SpawnPoint { get; set; }

    /// <summary>The client just opened a connection — handshake hasn't finished.</summary>
    public void OnConnected( Connection connection )
    {
        Log.Info( $"{connection.DisplayName} connected — handshaking..." );
    }

    /// <summary>The client is fully in. Spawn their player here.</summary>
    public void OnActive( Connection connection )
    {
        var player = PlayerPrefab.Clone( SpawnPoint.Transform.World );
        player.NetworkSpawn( connection );
    }

    /// <summary>The client left for any reason. Clean up.</summary>
    public void OnDisconnected( Connection connection )
    {
        Log.Info( $"{connection.DisplayName} left." );
    }
}

// Implement INetworkSpawn on a Component to react to its own object being networked.
public sealed class FlashOnSpawn : Component, Component.INetworkSpawn
{
    public void OnNetworkSpawn()
    {
        Log.Info( $"{GameObject.Name} just appeared on the network." );
    }
}

Place the GameNetworkManager component in your starting scene with PlayerPrefab and SpawnPoint wired up. New connections will auto-spawn a player on join and tear down on leave.

Related s&box Tools

s&box Network Events Reference — FAQ

Is this s&box Network Events Reference free to use?

Yes, the s&box Network Events Reference is 100% free — no signup required, no hidden fees, no downloads. Everything runs in your browser.

How accurate is the s&box Network Events Reference?

Values are pulled from the s&box game files and community-verified formulas. Results match what you see in-game, and we update the tool when the game gets major patches.

Can I host a s&box server with XGamingServer?

Yes. XGamingServer offers instant s&box server hosting with mod support, automatic backups, DDoS protection, and 24/7 support. All popular game settings are pre-configured.

Does the Network Events Reference work on mobile?

Yes, the Network Events Reference is fully responsive and works on desktop, tablet, and mobile browsers.

You might also need

Built-In Tool

Config Tool Built Into XGamingServer

Get managed s&box hosting with this tool in your panel — configure, deploy, and play in minutes. No file uploads needed.

Built-In Config ToolInstant Server SetupDDoS ProtectionExpert 24/7 Support
Get 40% OFFNo setup fees · Cancel anytime